qid
int64
4
8.14M
question
stringlengths
20
48.3k
answers
list
date
stringlengths
10
10
metadata
list
input
stringlengths
12
45k
output
stringlengths
2
31.8k
58,290
<p>How do I disable adding of new posts of a particular custom post type?</p> <p>Found this code in Log Deprecated Notices plugin:</p> <pre><code> $screen = get_current_screen(); if ( self::pt == $screen-&gt;id &amp;&amp; ( $screen-&gt;action == 'add' || $_GET['action'] == 'edit' ) ) wp_die( __( 'Inval...
[ { "answer_id": 58292, "author": "TheDeadMedic", "author_id": 1685, "author_profile": "https://wordpress.stackexchange.com/users/1685", "pm_score": 4, "selected": true, "text": "<p>As per <a href=\"https://stackoverflow.com/a/16675677/247223\">this answer</a>, the \"correct way\" is:</p>\...
2012/07/12
[ "https://wordpress.stackexchange.com/questions/58290", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/5844/" ]
How do I disable adding of new posts of a particular custom post type? Found this code in Log Deprecated Notices plugin: ``` $screen = get_current_screen(); if ( self::pt == $screen->id && ( $screen->action == 'add' || $_GET['action'] == 'edit' ) ) wp_die( __( 'Invalid post type.', 'log-deprecated' ) ...
As per [this answer](https://stackoverflow.com/a/16675677/247223), the "correct way" is: ``` register_post_type( 'custom_post_type_name', array( 'capability_type' => 'post', 'capabilities' => array( 'create_posts' => false, // Removes support for the "Add New" function ( use 'do_not_allow' instead of false for...
58,294
<p>I'm attempting to debug a unit test for a WordPress plugin. The unit test uses wordpress-test (and PHPUnit). However, <a href="https://github.com/nb/wordpress-tests" rel="nofollow noreferrer"><strong>wordpress-test</strong></a>:</p> <ol> <li>calls <code>system(php ...)</code> </li> <li>the new external PHP process ...
[ { "answer_id": 58320, "author": "KajMagnus", "author_id": 4211, "author_profile": "https://wordpress.stackexchange.com/users/4211", "pm_score": 3, "selected": true, "text": "<p>Now I've found a solution [to <strong>issue 2</strong> above]: I prefixed the external PHP command with: <code>...
2012/07/12
[ "https://wordpress.stackexchange.com/questions/58294", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/4211/" ]
I'm attempting to debug a unit test for a WordPress plugin. The unit test uses wordpress-test (and PHPUnit). However, [**wordpress-test**](https://github.com/nb/wordpress-tests): 1. calls `system(php ...)` 2. the new external PHP process attempts to connect to the *same debugger*, 3. but the debugger is already busy 4...
Now I've found a solution [to **issue 2** above]: I prefixed the external PHP command with: `XDEBUG_CONFIG="remote_enable=Off"` and then it didn't attempt to connect to the debugger. So, in `wordpress-tests/init.php` I changed from: ``` system( WP_PHP_BINARY . ' ' . escapeshellarg( dirname( __FILE__ ) . '/bin/...
58,306
<p>Is it possible to use the user-interface (front-end) part of Wordpress to open comments on all posts in one (or two) clicks? I have many posts with closed comments which must have happened by mistake, and I want to make them all open comments.</p> <p>Here's the caveat: My host provider doesn't give me <code>ssh</...
[ { "answer_id": 58310, "author": "Milo", "author_id": 4771, "author_profile": "https://wordpress.stackexchange.com/users/4771", "pm_score": 4, "selected": true, "text": "<p>I wrote up this quick plugin that updates all posts of type <code>post</code> to <code>comment_status</code> <code>o...
2012/07/12
[ "https://wordpress.stackexchange.com/questions/58306", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/8427/" ]
Is it possible to use the user-interface (front-end) part of Wordpress to open comments on all posts in one (or two) clicks? I have many posts with closed comments which must have happened by mistake, and I want to make them all open comments. Here's the caveat: My host provider doesn't give me `ssh` access into the d...
I wrote up this quick plugin that updates all posts of type `post` to `comment_status` `open` on activation, it should work for you. you can immediately deactivate and delete it once you activate it that once. ``` <?php /* Plugin Name: update comment status */ function activate_update_comment_status() { global $wp...
58,347
<p>I get this error in my theme:</p> <blockquote> <p>Catchable fatal error: Object of class WP_Error could not be converted to string in <code>/home/winentra/public_html/s1.ssonline.co.in/wp-content/themes/peekaboo/admin/common-functions.php</code> on line 186</p> </blockquote> <p>Line No. 186:</p> <pre><code>echo...
[ { "answer_id": 58349, "author": "fuxia", "author_id": 73, "author_profile": "https://wordpress.stackexchange.com/users/73", "pm_score": 1, "selected": false, "text": "<p>If you call <code>get_the_category()</code> without a parameter you have to use it in a loop – after <code>the_post();...
2012/07/13
[ "https://wordpress.stackexchange.com/questions/58347", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/15744/" ]
I get this error in my theme: > > Catchable fatal error: Object of class WP\_Error could not be converted to string in `/home/winentra/public_html/s1.ssonline.co.in/wp-content/themes/peekaboo/admin/common-functions.php` on line 186 > > > Line No. 186: ``` echo get_category_parents($cat, TRUE, ' ' . $delimiter . ...
If you call `get_the_category()` without a parameter you have to use it in a loop – after `the_post();` was called. Otherwise `get_the_category()` returns `FALSE` and `get_category_parents()` returns a `WP_Error` object … which is lacking a `toString()` method and therefore cannot be printed. So **test** if you get an...
58,351
<p>Some themes ask you not to edit the style.css file, instead use custom.css file. If you write code on custom.css, it will overwrite the same element style in style.css. I think this is done in order to prevent the loss of user styles on theme update, is it so?</p> <p><strong>How this works?</strong> Do they already...
[ { "answer_id": 58353, "author": "Wai Wong", "author_id": 18078, "author_profile": "https://wordpress.stackexchange.com/users/18078", "pm_score": 4, "selected": true, "text": "<p>I usually add this piece of code if I want to add another css file</p>\n\n<pre><code>&lt;link rel=\"stylesheet...
2012/07/13
[ "https://wordpress.stackexchange.com/questions/58351", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/17303/" ]
Some themes ask you not to edit the style.css file, instead use custom.css file. If you write code on custom.css, it will overwrite the same element style in style.css. I think this is done in order to prevent the loss of user styles on theme update, is it so? **How this works?** Do they already include custom.css fil...
I usually add this piece of code if I want to add another css file ``` <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/my_custom_css.css" type="text/css" media="screen" /> ``` I believe the theme makers want to retain as much as possible of the theme's layout design. So a custom css file doesn't ...
58,352
<p>This is my first time installing wordpress via FTP, and the first time to an existing host and domain (I normally use EvoHosting, since it's automatic)</p> <p>I've gotten to the stage where I'm heading to /wp-admin/install.php, but it's redirecting to the host - 123-reg.co.uk</p> <p>I'm trying to figure out where ...
[ { "answer_id": 58354, "author": "Damien", "author_id": 17132, "author_profile": "https://wordpress.stackexchange.com/users/17132", "pm_score": 0, "selected": false, "text": "<p>I use 123-reg for all my DNS stuff so I understand your predicament. </p>\n\n<p>I assume you are not using 123-...
2012/07/13
[ "https://wordpress.stackexchange.com/questions/58352", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18132/" ]
This is my first time installing wordpress via FTP, and the first time to an existing host and domain (I normally use EvoHosting, since it's automatic) I've gotten to the stage where I'm heading to /wp-admin/install.php, but it's redirecting to the host - 123-reg.co.uk I'm trying to figure out where I went wrong. I'...
I'm Nerys, I work here at 123-reg. It does indeed sound as if your domain name has not been pointed to your hosting package. Your hosting provider will be able to provide you with the details on the records you need to set up. This will usually be changing the nameservers, or setting an A record. I have included links ...
58,365
<p>The custom header feature allows (in some code I have found) to suggest several default images to use in the custom header.</p> <p>Could the same be built in the custom background?</p> <p>The idea is to have already some textures available for the user to choose from in the theme.</p> <p>Any ideas?</p>
[ { "answer_id": 58368, "author": "Krimo", "author_id": 11611, "author_profile": "https://wordpress.stackexchange.com/users/11611", "pm_score": 0, "selected": false, "text": "<p>I would suggest outputting a line of CSS in your header.php file, something like</p>\n\n<pre><code>&lt;?='.body ...
2012/07/13
[ "https://wordpress.stackexchange.com/questions/58365", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18137/" ]
The custom header feature allows (in some code I have found) to suggest several default images to use in the custom header. Could the same be built in the custom background? The idea is to have already some textures available for the user to choose from in the theme. Any ideas?
if you are asking default background image for `add_theme_support( 'custom-background');` then it can be set using `'default-image' => get_template_directory_uri() . '/images/pattern.png',` complete code will look like below. ``` $args = array( 'default-color' => 'f0f0f0', 'default-repeat' => 'fixed', 'default-image...
58,367
<p>I'm trying to use the <code>get_image_tag()</code> function to alter the html output of an image, like so :</p> <pre><code>add_filter('get_image_tag', 'kh_image_attachment', 10, 5); function kh_image_attachment($html, $id, $alt, $title, $align) { $html = '&lt;img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5B...
[ { "answer_id": 58372, "author": "janw", "author_id": 10911, "author_profile": "https://wordpress.stackexchange.com/users/10911", "pm_score": 1, "selected": false, "text": "<p>try the below:<br/>\nYou use a filter with more then one arg, <code>add_filter</code> by default will give 1 arg,...
2012/07/13
[ "https://wordpress.stackexchange.com/questions/58367", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/11611/" ]
I'm trying to use the `get_image_tag()` function to alter the html output of an image, like so : ``` add_filter('get_image_tag', 'kh_image_attachment', 10, 5); function kh_image_attachment($html, $id, $alt, $title, $align) { $html = '<img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAO...
Solution: ========= I needed to use the `wp_get_attachment_image_src` function. ``` add_filter('get_image_tag', 'kh_image_attachment', 10, 5); function kh_image_attachment($html, $id, $alt, $title, $align) { $image_source = wp_get_attachment_image_src( $id, 'full' ); $html = '<img src="data:image/gif;base64,R...
58,373
<p>All the comments on my website are anonymous and without registration. To post a comment you have to fill the fields name (not obligatorily) and the text of your comment (obligatorily).</p> <p>I have the problem with the avatars. All of them are generated the same.</p> <p>What should I do to make them different?</...
[ { "answer_id": 58393, "author": "fuxia", "author_id": 73, "author_profile": "https://wordpress.stackexchange.com/users/73", "pm_score": 4, "selected": true, "text": "<p>There are two ways to customize the default avatar:</p>\n\n<ol>\n<li>Add a new default avatar to <em>Settings/Discussio...
2012/07/13
[ "https://wordpress.stackexchange.com/questions/58373", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/5645/" ]
All the comments on my website are anonymous and without registration. To post a comment you have to fill the fields name (not obligatorily) and the text of your comment (obligatorily). I have the problem with the avatars. All of them are generated the same. What should I do to make them different?
There are two ways to customize the default avatar: 1. Add a new default avatar to *Settings/Discussion*. 2. Change the output of `get_avatar()`. Let’s start with the first option; this processes slightly faster. Add a new default avatar to *Settings/Discussion* ------------------------------------------------- The...
58,377
<p>Genesis framework applies filters to the wp_nav_menu(). What I want to do is 2 things.</p> <p>1 change the menu class via a filter</p> <p>2 add a menu id via a filter</p> <p>Here is the function I am trying to add a filter to.</p> <pre><code> add_action( 'genesis_after_header', 'genesis_do_nav' ); /** * Echoes ...
[ { "answer_id": 58394, "author": "Evan Mattson", "author_id": 12055, "author_profile": "https://wordpress.stackexchange.com/users/12055", "pm_score": 2, "selected": false, "text": "<p>The function that Genesis gives you to use does not give you the option of altering those args before the...
2012/07/13
[ "https://wordpress.stackexchange.com/questions/58377", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/370/" ]
Genesis framework applies filters to the wp\_nav\_menu(). What I want to do is 2 things. 1 change the menu class via a filter 2 add a menu id via a filter Here is the function I am trying to add a filter to. ``` add_action( 'genesis_after_header', 'genesis_do_nav' ); /** * Echoes the "Primary Navigation" menu. *...
This new updated version of Evan's Code works with Genesis 1.9 and fixes the bug of displaying all navigation items. ``` /* * Add classes to Genesis Navigation * Tested with Genesis 1.9 (Beta) * 29.12.2012 */ add_filter( 'genesis_do_nav', 'override_do_nav', 10, 3 ); function override_do_nav($nav_output, $nav, $arg...
58,391
<p>One of the most common security best practices these days seems to be <a href="http://codex.wordpress.org/Hardening_WordPress#Securing_wp-config.php" rel="noreferrer">moving <code>wp-config.php</code> one directory higher than the vhost's document root</a>. I've never really found a good explanation for that, but I'...
[ { "answer_id": 58397, "author": "Max Yudin", "author_id": 11761, "author_profile": "https://wordpress.stackexchange.com/users/11761", "pm_score": 4, "selected": false, "text": "<p>Definitely YES.</p>\n\n<p>When you move <em>wp-config.php</em> outside public directory you protect it from ...
2012/07/13
[ "https://wordpress.stackexchange.com/questions/58391", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/3898/" ]
One of the most common security best practices these days seems to be [moving `wp-config.php` one directory higher than the vhost's document root](http://codex.wordpress.org/Hardening_WordPress#Securing_wp-config.php). I've never really found a good explanation for that, but I'm assuming it's to minimize the risk of a ...
Short answer: yes ================= The answer to this question is **yes** and to say otherwise is **probably irresponsible**. --- Long answer: a real-world example ================================= Allow me to provide a very real example, from my very real server, where moving `wp-config.php` outside the web root ...
58,395
<p>I've written a small posts by views plugin, well at least started one.</p> <p>My tables are set up but when they are updated the code adds 2 entries into my table when a post is loaded and views are tracked. I literally have no idea why this is happening. It looks like the second post id entered into the DB table i...
[ { "answer_id": 147905, "author": "J.D.", "author_id": 27757, "author_profile": "https://wordpress.stackexchange.com/users/27757", "pm_score": 1, "selected": false, "text": "<p>Sounds like browser prefetching, see WordPress core tickets <a href=\"https://core.trac.wordpress.org/ticket/126...
2012/07/13
[ "https://wordpress.stackexchange.com/questions/58395", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/5391/" ]
I've written a small posts by views plugin, well at least started one. My tables are set up but when they are updated the code adds 2 entries into my table when a post is loaded and views are tracked. I literally have no idea why this is happening. It looks like the second post id entered into the DB table is the post...
Sounds like browser prefetching, see WordPress core tickets [#12603](https://core.trac.wordpress.org/ticket/12603), [#14382](https://core.trac.wordpress.org/ticket/14382), and [#20192](https://core.trac.wordpress.org/ticket/20192). Basically, sometimes some browsers see what the next post is, and decide to go ahead an...
58,429
<p>The current result is "PHP Fatal error: Call to undefined function wp_get_current_user()" which makes sense, but doesn't help.</p> <p>I need to use $current_user.</p> <p>Here is the code I'm currently using:</p> <pre><code>$wp-&gt;init(); do_action( 'init' ); // Check site status $file='http://xxxxxxxx.com/wp-...
[ { "answer_id": 58436, "author": "Laurence Tuck", "author_id": 1426, "author_profile": "https://wordpress.stackexchange.com/users/1426", "pm_score": 0, "selected": false, "text": "<p>It looks like you're loading your code before certain functions are available. Have you tried: </p>\n\n<pr...
2012/07/13
[ "https://wordpress.stackexchange.com/questions/58429", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18152/" ]
The current result is "PHP Fatal error: Call to undefined function wp\_get\_current\_user()" which makes sense, but doesn't help. I need to use $current\_user. Here is the code I'm currently using: ``` $wp->init(); do_action( 'init' ); // Check site status $file='http://xxxxxxxx.com/wp-admin/wp_includes/pluggable....
To add to @EAMann's answer, you need to wrap your `wp_get_current_user()` call (or any call that tries to access a function defined within `pluggable.php`) within the `'plugins_loaded'` action. So, if you're putting this inside your `functions.php` file, do it like this: ``` add_action( 'plugins_loaded', 'get_user_in...
58,453
<p>I want to use another link for logout because I have <code>/wp-admin/*</code> protected with htpassword. Is there a way to do this? Something like creating a custom page like <code>site.com/logout</code> then use it as my new logout link?</p> <p>Thanks!</p>
[ { "answer_id": 58454, "author": "fuxia", "author_id": 73, "author_profile": "https://wordpress.stackexchange.com/users/73", "pm_score": 2, "selected": false, "text": "<p>You can filter <code>'logout_url'</code> and return a custom value if you are in the admin area:</p>\n\n<pre><code>add...
2012/07/14
[ "https://wordpress.stackexchange.com/questions/58453", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/17721/" ]
I want to use another link for logout because I have `/wp-admin/*` protected with htpassword. Is there a way to do this? Something like creating a custom page like `site.com/logout` then use it as my new logout link? Thanks!
You can filter `'logout_url'` and return a custom value if you are in the admin area: ``` add_filter( 'logout_url', 'wpse_58453_logout_url' ); function wpse_58453_logout_url( $default ) { // set your URL here return is_admin() ? 'http://example.com/custom' : $default; } ```
58,464
<pre><code>&lt;?php $categories1=get_categories('orderby=post_date&amp;order=DESC'); function filter_where( $where = '' ) { $today = date('Y-m-d', current_time( 'timestamp' )); $yesterday = strtotime ( '-1 day' , strtotime ( $today ) ) ; $yesterday = date('Y-m-d', $yesterday); $where .= " AND post_date &gt;= '" . $yes...
[ { "answer_id": 58454, "author": "fuxia", "author_id": 73, "author_profile": "https://wordpress.stackexchange.com/users/73", "pm_score": 2, "selected": false, "text": "<p>You can filter <code>'logout_url'</code> and return a custom value if you are in the admin area:</p>\n\n<pre><code>add...
2012/07/14
[ "https://wordpress.stackexchange.com/questions/58464", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/17742/" ]
``` <?php $categories1=get_categories('orderby=post_date&order=DESC'); function filter_where( $where = '' ) { $today = date('Y-m-d', current_time( 'timestamp' )); $yesterday = strtotime ( '-1 day' , strtotime ( $today ) ) ; $yesterday = date('Y-m-d', $yesterday); $where .= " AND post_date >= '" . $yesterday . "'" . " ...
You can filter `'logout_url'` and return a custom value if you are in the admin area: ``` add_filter( 'logout_url', 'wpse_58453_logout_url' ); function wpse_58453_logout_url( $default ) { // set your URL here return is_admin() ? 'http://example.com/custom' : $default; } ```
58,470
<p>I am trying to hack the default categories widget from wordpress. I have the categories displaying the way I want but I am having trouble editing the output. The widget shows the number of posts in each post which is what I want, but it also displays the number in parenthesis. I don't want that. I know how to get ri...
[ { "answer_id": 58495, "author": "Milo", "author_id": 4771, "author_profile": "https://wordpress.stackexchange.com/users/4771", "pm_score": 1, "selected": true, "text": "<p><code>wp_list_categories</code> echoes output by default, your <code>str_replace</code> isn't working because nothin...
2012/07/14
[ "https://wordpress.stackexchange.com/questions/58470", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/14761/" ]
I am trying to hack the default categories widget from wordpress. I have the categories displaying the way I want but I am having trouble editing the output. The widget shows the number of posts in each post which is what I want, but it also displays the number in parenthesis. I don't want that. I know how to get rid o...
`wp_list_categories` echoes output by default, your `str_replace` isn't working because nothing was assigned to `$list`.
58,471
<p>I have static front-page and separate page <code>/news/</code> as the Posts page. I would like to have the single-post URLs like this:</p> <pre><code>www.example.com/news/categoryname/subcategory/postname/ </code></pre> <p>and for the category archives:</p> <pre><code>www.example.com/news/categoryname/ </code></p...
[ { "answer_id": 62608, "author": "Leo Eidinov", "author_id": 19539, "author_profile": "https://wordpress.stackexchange.com/users/19539", "pm_score": 0, "selected": false, "text": "<p>Custom permalink structure: <code>/media/%category%/%postname%/</code>\nCategory base: <code>.</code></p>\...
2012/07/14
[ "https://wordpress.stackexchange.com/questions/58471", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18164/" ]
I have static front-page and separate page `/news/` as the Posts page. I would like to have the single-post URLs like this: ``` www.example.com/news/categoryname/subcategory/postname/ ``` and for the category archives: ``` www.example.com/news/categoryname/ ``` What I've tried already: * If I add `news` as my ca...
I returned to this problem recently and I've found the solution finally! It may or may not work for you - there are two possible cases: 1. If some posts on your site are placed under parent categories and some - in subcategories (child categories), or the categories have different nesting levels (some parent categorie...
58,480
<p>I want to have a related box to show up - but only if a related post is inside the div. If theres no post the whole "related_box" div should be not shown. Any idea? </p> <p>Here's the code so far.</p> <pre><code> &lt;div id="related_box" class="related"&gt; &lt;div class="movie_header"&gt; &lt;div id="f...
[ { "answer_id": 58483, "author": "Damien", "author_id": 17132, "author_profile": "https://wordpress.stackexchange.com/users/17132", "pm_score": 0, "selected": false, "text": "<p>It might sound odd ... but you are so close</p>\n\n<p>in fact a standard single.php template usually has a loop...
2012/07/14
[ "https://wordpress.stackexchange.com/questions/58480", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/17376/" ]
I want to have a related box to show up - but only if a related post is inside the div. If theres no post the whole "related\_box" div should be not shown. Any idea? Here's the code so far. ``` <div id="related_box" class="related"> <div class="movie_header"> <div id="featured"><h2>Related</h2> </di...
move the div section from the start to after the `if(have_posts()) {` line, and move the corresponding closing divs to just before the closing bracket `}` of this if statement; full code: ``` <?php global $post; $terms = get_the_terms( $post->ID , 'movies', 'string'); $do_not_duplicate[] = $pos...
58,482
<p>I created a WordPress page template to build a customised XML feed for certain WordPress posts on my site. Specifically, the page template renders XML and only includes certain custom post types and only if these posts contain specific meta data.</p> <p>I'm using the data to feed WordPress content to an iOS applica...
[ { "answer_id": 58484, "author": "Damien", "author_id": 17132, "author_profile": "https://wordpress.stackexchange.com/users/17132", "pm_score": 1, "selected": false, "text": "<p>you can hook up Transient API for this and store the results of the wp_query in your database for 1 - 2 hours ....
2012/07/14
[ "https://wordpress.stackexchange.com/questions/58482", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/1341/" ]
I created a WordPress page template to build a customised XML feed for certain WordPress posts on my site. Specifically, the page template renders XML and only includes certain custom post types and only if these posts contain specific meta data. I'm using the data to feed WordPress content to an iOS application. It s...
Not sure how dramatic this'll be, but it should improve nontheless: ``` <?php /** * You can try forcibly splitting the query (grabbing IDs *then* all fields) * Works well for large post results. (available WP 3.4+) */ add_filter( 'split_the_query', '__return_true' ); $posts = get_posts( array( 'post_type' ...
58,486
<p>I'm building a city portal/ social business directory with buddypress and wordpress. All business listings are stored as a custom post type called 'business'. I'm using the following code to show the activity related to business listings in the activity stream</p> <pre><code>function bbg_record_my_custom_post_type_...
[ { "answer_id": 58675, "author": "shanebp", "author_id": 16575, "author_profile": "https://wordpress.stackexchange.com/users/16575", "pm_score": 3, "selected": true, "text": "<p>You can filter on the action before it is saved by using add_filter on \n'bp_blogs_activity_new_comment_action'...
2012/07/14
[ "https://wordpress.stackexchange.com/questions/58486", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/12357/" ]
I'm building a city portal/ social business directory with buddypress and wordpress. All business listings are stored as a custom post type called 'business'. I'm using the following code to show the activity related to business listings in the activity stream ``` function bbg_record_my_custom_post_type_comments( $pos...
You can filter on the action before it is saved by using add\_filter on 'bp\_blogs\_activity\_new\_comment\_action' as shown in bp-blogs-functions.php -> bp\_blogs\_record\_comment() Or you can filter before the action is displayed by using add\_filter on 'bp\_get\_activity\_action' Probably better to do the forme...
58,496
<p>So basically, I have posts assigned to only subcategories and not to categories (this is so both of them get displayed in the premalink) and in the post page only the subcategory is displayed. I want to to display the parent category somewhere on the post page also.</p> <p>I need something like this:</p> <pre><co...
[ { "answer_id": 58498, "author": "Milo", "author_id": 4771, "author_profile": "https://wordpress.stackexchange.com/users/4771", "pm_score": 1, "selected": false, "text": "<p>in your <code>foreach</code> you assign <code>get_the_category()</code> to <code>$category</code>, but then inside ...
2012/07/14
[ "https://wordpress.stackexchange.com/questions/58496", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/13114/" ]
So basically, I have posts assigned to only subcategories and not to categories (this is so both of them get displayed in the premalink) and in the post page only the subcategory is displayed. I want to to display the parent category somewhere on the post page also. I need something like this: ``` Sample Post belongs...
in your `foreach` you assign `get_the_category()` to `$category`, but then inside `get_category_parents()`, you pass `$cat` instead of `$category`.
58,501
<p>I would like to remove the visual editor from one specific page because if I edit this one page in Visual mode, it breaks the code. I want to make sure the client doesn't have this option on the particular page. However, I don't want to remove the html editor.</p> <p>This line of code removes the visual editor and ...
[ { "answer_id": 58502, "author": "brasofilo", "author_id": 12615, "author_profile": "https://wordpress.stackexchange.com/users/12615", "pm_score": 4, "selected": true, "text": "<p>In your code, calling the action <code>admin_init</code> makes <code>is_admin()</code> unnecessary. And, if n...
2012/07/14
[ "https://wordpress.stackexchange.com/questions/58501", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/15259/" ]
I would like to remove the visual editor from one specific page because if I edit this one page in Visual mode, it breaks the code. I want to make sure the client doesn't have this option on the particular page. However, I don't want to remove the html editor. This line of code removes the visual editor and the html e...
In your code, calling the action `admin_init` makes `is_admin()` unnecessary. And, if not mistaken, [`is_page()`](http://codex.wordpress.org/Function_Reference/is_page) is meant to be used in the front-end... But the solution is the following (based on [this Answer](https://wordpress.stackexchange.com/a/18149/12615)):...
58,511
<p>I am using this code here: </p> <pre><code>&lt;?php $trim_length = 25; //desired length of text to display $custom_field = 'my-custom-field-name'; $value = get_post_meta($post-&gt;ID, $custom_field, true); if ($value) { echo rtrim(substr($value,0,$trim_length)); } ?&gt; </code></pre> <p>It works - but I would li...
[ { "answer_id": 58512, "author": "keatch", "author_id": 2727, "author_profile": "https://wordpress.stackexchange.com/users/2727", "pm_score": 0, "selected": false, "text": "<p>Try this code.</p>\n\n<p>You must check if the string was trimmed. If it is, is length is <code>$trim_length</cod...
2012/07/14
[ "https://wordpress.stackexchange.com/questions/58511", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/17376/" ]
I am using this code here: ``` <?php $trim_length = 25; //desired length of text to display $custom_field = 'my-custom-field-name'; $value = get_post_meta($post->ID, $custom_field, true); if ($value) { echo rtrim(substr($value,0,$trim_length)); } ?> ``` It works - but I would like to have a "(...)" at the end of ...
building on keatch's answer you only need to trim if its longer the 25 chars so: ``` $trim_length = 25; //desired length of text to display $custom_field = 'my-custom-field-name'; $value = get_post_meta($post->ID, $custom_field, true); if ($value) { if (strlen($value) > $trim_length) $value = rtrim(substr...
58,524
<p>I've created a hierarchical custom taxonomy (genre) and want to use it for a custom post type (radio station). But I don't only want to assign some genres to a radio station. I also want to be able to select one major/main genre as "most important genre" for each radio station.</p> <p>Is it possible to do add a (na...
[ { "answer_id": 58527, "author": "brasofilo", "author_id": 12615, "author_profile": "https://wordpress.stackexchange.com/users/12615", "pm_score": 2, "selected": false, "text": "<p>If I understand your question correctly, then it's a matter of joining the code from two answers from the fo...
2012/07/14
[ "https://wordpress.stackexchange.com/questions/58524", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18118/" ]
I've created a hierarchical custom taxonomy (genre) and want to use it for a custom post type (radio station). But I don't only want to assign some genres to a radio station. I also want to be able to select one major/main genre as "most important genre" for each radio station. Is it possible to do add a (native) "sel...
If I understand your question correctly, then it's a matter of joining the code from two answers from the following Questions of this Stack: * [Changing Top Level Items into Radio Buttons in the Categories Meta Box?](https://wordpress.stackexchange.com/q/30036/12615) * [Make parent categories not selectable](https://...
58,545
<p>In desperation I am asking for help in this forum too - if someone (ANYONE!) could take a look a this post and see if they could help I'd be eternally grateful</p> <p><a href="http://wordpress.org/support/topic/wp_update_user-not-updating?replies=11" rel="noreferrer">http://wordpress.org/support/topic/wp_update_use...
[ { "answer_id": 58552, "author": "Pontus Abrahamsson", "author_id": 16722, "author_profile": "https://wordpress.stackexchange.com/users/16722", "pm_score": 2, "selected": false, "text": "<p>Im using <code>remove_role</code> and then <code>add_role</code> to upgrade a user from one role to...
2012/07/15
[ "https://wordpress.stackexchange.com/questions/58545", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18189/" ]
In desperation I am asking for help in this forum too - if someone (ANYONE!) could take a look a this post and see if they could help I'd be eternally grateful <http://wordpress.org/support/topic/wp_update_user-not-updating?replies=11> Basically - I am updating a user's role and capabilities via script but the change...
Im using `remove_role` and then `add_role` to upgrade a user from one role to another. Here is a function that checks all user within the user role **subscriber** and upgrade them to **editor** every hour. ``` /** * Add a cron job that will update * Subscribers to editors. Runs hourly */ add_action('check_user_role'...
58,547
<p>In my slider.php I have a loop that calls for a custom post type. That custom post type has a meta box for a slide url (link/title/etc). I can see the loop and everything else is working because in the source code it shows the corrent url from the meta box. But it will NOT load the slider. But lets say I drop a dire...
[ { "answer_id": 58588, "author": "Wyck", "author_id": 1509, "author_profile": "https://wordpress.stackexchange.com/users/1509", "pm_score": 0, "selected": false, "text": "<p>This line looks like a problem</p>\n\n<pre><code>&lt;?php $slide_img_src = smc_get_the_slide_img_source(); ?&gt;\n<...
2012/07/15
[ "https://wordpress.stackexchange.com/questions/58547", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18191/" ]
In my slider.php I have a loop that calls for a custom post type. That custom post type has a meta box for a slide url (link/title/etc). I can see the loop and everything else is working because in the source code it shows the corrent url from the meta box. But it will NOT load the slider. But lets say I drop a direct ...
The simplest explanation is that the HTML rendered in your code does not match what you're actually looking for. Without seeing the JS responsible for the slider, it's impossible to say where you went wrong, but you should compare the mocked-up version (that works) with what you're actually getting (HTML source after p...
58,558
<p>I've created my wordpress theme from the default Twenty Eleven theme, and I want to show a different sidebar on a few pages. I found <a href="http://ablereach.com/wordpress/wordpress-add-a-second-widget-ready-sidebar/" rel="nofollow">this tutorial</a> but it really doesn't answer my question. </p> <p>So, I need a s...
[ { "answer_id": 58588, "author": "Wyck", "author_id": 1509, "author_profile": "https://wordpress.stackexchange.com/users/1509", "pm_score": 0, "selected": false, "text": "<p>This line looks like a problem</p>\n\n<pre><code>&lt;?php $slide_img_src = smc_get_the_slide_img_source(); ?&gt;\n<...
2012/07/15
[ "https://wordpress.stackexchange.com/questions/58558", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/-1/" ]
I've created my wordpress theme from the default Twenty Eleven theme, and I want to show a different sidebar on a few pages. I found [this tutorial](http://ablereach.com/wordpress/wordpress-add-a-second-widget-ready-sidebar/) but it really doesn't answer my question. So, I need a sidebar that is shown on admin panel ...
The simplest explanation is that the HTML rendered in your code does not match what you're actually looking for. Without seeing the JS responsible for the slider, it's impossible to say where you went wrong, but you should compare the mocked-up version (that works) with what you're actually getting (HTML source after p...
58,573
<p>Is there a straightforward way to share/sync multiple WP instances with a single database? I work collaboratively with several developers on custom themed sites. We use git to keep our files in order and it's all fine in the early stages, but once content, plugins etc. start coming into play, we have issues with sta...
[ { "answer_id": 58581, "author": "vmassuchetto", "author_id": 7385, "author_profile": "https://wordpress.stackexchange.com/users/7385", "pm_score": 4, "selected": true, "text": "<p>Yes. Use <code>WP_HOME</code> and <code>WP_SITEURL</code> in your <code>wp-config.php</code>, so the URLs in...
2012/07/15
[ "https://wordpress.stackexchange.com/questions/58573", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/15190/" ]
Is there a straightforward way to share/sync multiple WP instances with a single database? I work collaboratively with several developers on custom themed sites. We use git to keep our files in order and it's all fine in the early stages, but once content, plugins etc. start coming into play, we have issues with stayin...
Yes. Use `WP_HOME` and `WP_SITEURL` in your `wp-config.php`, so the URLs in the database won't mess (a lot) with local site development. ``` define ('WP_HOME', 'http://local/site/url'); define ('WP_SITEURL', 'http://local/site/url'); ``` Also, some other good practices: * Put in your `.gitignore` things like: ``` ...
58,577
<p>I have been using this code to display my wordpress navigation and it worked;</p> <pre><code>&lt;ul id="menu"&gt; &lt;?php wp_list_pages('sort_column=menu_order&amp;title_li='); ?&gt; &lt;/ul&gt; </code></pre> <p>However,i want to use register_nav_menus so that i can arrange my menus from the wp backend.I have thi...
[ { "answer_id": 58581, "author": "vmassuchetto", "author_id": 7385, "author_profile": "https://wordpress.stackexchange.com/users/7385", "pm_score": 4, "selected": true, "text": "<p>Yes. Use <code>WP_HOME</code> and <code>WP_SITEURL</code> in your <code>wp-config.php</code>, so the URLs in...
2012/07/15
[ "https://wordpress.stackexchange.com/questions/58577", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/11125/" ]
I have been using this code to display my wordpress navigation and it worked; ``` <ul id="menu"> <?php wp_list_pages('sort_column=menu_order&title_li='); ?> </ul> ``` However,i want to use register\_nav\_menus so that i can arrange my menus from the wp backend.I have this code and its not working as expected; ``` <...
Yes. Use `WP_HOME` and `WP_SITEURL` in your `wp-config.php`, so the URLs in the database won't mess (a lot) with local site development. ``` define ('WP_HOME', 'http://local/site/url'); define ('WP_SITEURL', 'http://local/site/url'); ``` Also, some other good practices: * Put in your `.gitignore` things like: ``` ...
58,584
<p>It is possible send email for deleting account on wordpress??</p> <p>Like this: <a href="https://i.stack.imgur.com/Lt6Ks.png" rel="nofollow noreferrer">http://i.stack.imgur.com/Lt6Ks.png</a></p> <p>Ok after click send email to user with ex text: "your account has been deleted" ??</p>
[ { "answer_id": 58587, "author": "Barry Carlyon", "author_id": 14034, "author_profile": "https://wordpress.stackexchange.com/users/14034", "pm_score": 3, "selected": true, "text": "<p>Yes. The full answer is here in the codex: <a href=\"http://codex.wordpress.org/Plugin_API/Action_Referen...
2012/07/15
[ "https://wordpress.stackexchange.com/questions/58584", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18205/" ]
It is possible send email for deleting account on wordpress?? Like this: [http://i.stack.imgur.com/Lt6Ks.png](https://i.stack.imgur.com/Lt6Ks.png) Ok after click send email to user with ex text: "your account has been deleted" ??
Yes. The full answer is here in the codex: <http://codex.wordpress.org/Plugin_API/Action_Reference/delete_user> ~~So I won't repost its code.~~ ``` function my_delete_user($user_id) { global $wpdb; $email = $wpdb->get_var("SELECT user_email FROM $wpdb->users WHERE ID = '" . $user_id . "' LIMIT 1"); $hea...
58,593
<p>I already have a function where a user submits a form and creates a custom post...</p> <pre><code>&lt;?php $postTitle = $_POST['post_title']; $submit = $_POST['submit']; if(isset($submit)){ global $user_ID; $new_post = array( 'post_title' =&gt; $postTitle, 'post_content' =&gt; '', ...
[ { "answer_id": 58596, "author": "Barry Carlyon", "author_id": 14034, "author_profile": "https://wordpress.stackexchange.com/users/14034", "pm_score": 4, "selected": true, "text": "<p>This would need a query.</p>\n\n<p>So building on your code:</p>\n\n<pre><code>&lt;?php\n$postTitle = $_P...
2012/07/15
[ "https://wordpress.stackexchange.com/questions/58593", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/13545/" ]
I already have a function where a user submits a form and creates a custom post... ``` <?php $postTitle = $_POST['post_title']; $submit = $_POST['submit']; if(isset($submit)){ global $user_ID; $new_post = array( 'post_title' => $postTitle, 'post_content' => '', 'post_status' => 'publ...
This would need a query. So building on your code: ``` <?php $postTitle = $_POST['post_title']; $submit = $_POST['submit']; if(isset($submit)){ global $user_ID, $wpdb; $query = $wpdb->prepare( 'SELECT ID FROM ' . $wpdb->posts . ' WHERE post_title = %s AND post_type = \'stuff\'', ...
58,598
<p>So I have a problem when making a post. If I press enter and make a new line in the editor and press safe the line break diapers. But when I show the post it have inserted a line break. So somehow the editor is not able to show the line break? If I save the editor again the line break disappears from the post as wel...
[ { "answer_id": 58596, "author": "Barry Carlyon", "author_id": 14034, "author_profile": "https://wordpress.stackexchange.com/users/14034", "pm_score": 4, "selected": true, "text": "<p>This would need a query.</p>\n\n<p>So building on your code:</p>\n\n<pre><code>&lt;?php\n$postTitle = $_P...
2012/07/15
[ "https://wordpress.stackexchange.com/questions/58598", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18148/" ]
So I have a problem when making a post. If I press enter and make a new line in the editor and press safe the line break diapers. But when I show the post it have inserted a line break. So somehow the editor is not able to show the line break? If I save the editor again the line break disappears from the post as well. ...
This would need a query. So building on your code: ``` <?php $postTitle = $_POST['post_title']; $submit = $_POST['submit']; if(isset($submit)){ global $user_ID, $wpdb; $query = $wpdb->prepare( 'SELECT ID FROM ' . $wpdb->posts . ' WHERE post_title = %s AND post_type = \'stuff\'', ...
58,605
<p>I want to insert an ad code in the middle of a post via <code>functions.php</code>.</p> <p>I found several links but either they don't use <code>functions.php</code> or don't insert the code in the middle.</p> <p>Can anyone tell me how to do this?</p> <p>Also, I don't want to use a plugin.</p>
[ { "answer_id": 58611, "author": "Patrick D'appollonio", "author_id": 13042, "author_profile": "https://wordpress.stackexchange.com/users/13042", "pm_score": 2, "selected": false, "text": "<p>There are several alternatives:</p>\n\n<p>First, you can use shortcodes as @iambriansreed suggest...
2012/07/15
[ "https://wordpress.stackexchange.com/questions/58605", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/11998/" ]
I want to insert an ad code in the middle of a post via `functions.php`. I found several links but either they don't use `functions.php` or don't insert the code in the middle. Can anyone tell me how to do this? Also, I don't want to use a plugin.
This function inserts your ad code after the specified paragraph. ``` add_filter('the_content', 'wpse_ad_content'); function wpse_ad_content($content) { if (!is_single()) return $content; $paragraphAfter = 2; //Enter number of paragraphs to display ad after. $content = explode("</p>", $content); $new_...
58,621
<p>So I have this Wordpress blog at <a href="http://ilovetheupperwestside.com" rel="nofollow">ilovetheupperwestside.com</a>. It uses the Aggregate Theme from Elegant Themes.<br> I moved it from a temporary location to the current URL. </p> <p>This action broke some things, but thanks to a plugin called "Velvet Blues U...
[ { "answer_id": 58611, "author": "Patrick D'appollonio", "author_id": 13042, "author_profile": "https://wordpress.stackexchange.com/users/13042", "pm_score": 2, "selected": false, "text": "<p>There are several alternatives:</p>\n\n<p>First, you can use shortcodes as @iambriansreed suggest...
2012/07/13
[ "https://wordpress.stackexchange.com/questions/58621", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18228/" ]
So I have this Wordpress blog at [ilovetheupperwestside.com](http://ilovetheupperwestside.com). It uses the Aggregate Theme from Elegant Themes. I moved it from a temporary location to the current URL. This action broke some things, but thanks to a plugin called "Velvet Blues Update URLs" and a (serialization safe...
This function inserts your ad code after the specified paragraph. ``` add_filter('the_content', 'wpse_ad_content'); function wpse_ad_content($content) { if (!is_single()) return $content; $paragraphAfter = 2; //Enter number of paragraphs to display ad after. $content = explode("</p>", $content); $new_...
58,625
<p>I see that I can edit permalink information in wp-admin page > settings > permalinks. However, where is that information actually stored in the database?</p>
[ { "answer_id": 58626, "author": "Alexander Bird", "author_id": 9142, "author_profile": "https://wordpress.stackexchange.com/users/9142", "pm_score": 4, "selected": false, "text": "<p>In the <code>wp_options</code> table there is a record where <code>option_name = \"permalink_structure\"<...
2012/07/16
[ "https://wordpress.stackexchange.com/questions/58625", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/9142/" ]
I see that I can edit permalink information in wp-admin page > settings > permalinks. However, where is that information actually stored in the database?
In the `wp_options` table there is a record where `option_name = "permalink_structure"`. However, the true, ultimate control of url rewriting is controlled by the [WP\_Rewrite API](http://codex.wordpress.org/Function_Reference/WP_Rewrite) which saves/caches its information in the `rewrite_rules` wordpress option (also...
58,630
<p>How do I go about inserting a custom div before the wp_nav_menu() adds the ul?</p> <p>The problem is that the script is inserting my 'div menu button' after the nav ul instead of before it.</p> <p>I am trying to do this via a function because the basic idea is that on some of my menus I need to insert a div with a...
[ { "answer_id": 58631, "author": "Chip Bennett", "author_id": 3966, "author_profile": "https://wordpress.stackexchange.com/users/3966", "pm_score": 2, "selected": false, "text": "<blockquote>\n <p>How do I go about inserting a custom div before the wp_nav_menu() adds the ul?</p>\n</block...
2012/07/16
[ "https://wordpress.stackexchange.com/questions/58630", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/370/" ]
How do I go about inserting a custom div before the wp\_nav\_menu() adds the ul? The problem is that the script is inserting my 'div menu button' after the nav ul instead of before it. I am trying to do this via a function because the basic idea is that on some of my menus I need to insert a div with a 'menu' button ...
Here is the solution. Props to @SergeyBiryukov Changes required turning echo to false and adding in the return $main\_menu. ``` function tumble_menu( $args = array() ) { /* Default arguments */ $defaults = array( 'container' => 'ul', 'menu_class' => 'nav', 'menu_id' ...
58,632
<p>A theme I am developing depends on there being a static front page. However, there seems to only be one global option to change if front page is static. So when I go to preview the theme, it won't work because the front-page option is off. But I don't want to change the front-page option because the live site will b...
[ { "answer_id": 58635, "author": "Alexander Bird", "author_id": 9142, "author_profile": "https://wordpress.stackexchange.com/users/9142", "pm_score": 0, "selected": false, "text": "<p>What I did was this: I just manually coded <code>index.php</code> to be a copy/paste of <code>page.php</c...
2012/07/16
[ "https://wordpress.stackexchange.com/questions/58632", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/9142/" ]
A theme I am developing depends on there being a static front page. However, there seems to only be one global option to change if front page is static. So when I go to preview the theme, it won't work because the front-page option is off. But I don't want to change the front-page option because the live site will be a...
You can try the [Theme Test Drive](http://wordpress.org/plugins/theme-test-drive/) plugin to help you preview a development copy of your theme while a live site is still fully functional. Assuming it's the same theme you are working on (as it sounds like it) - you can copy the existing theme to a new theme folder, an...
58,633
<p>I'm looking for a way to add a new kind of control to the customize <em>live preview</em> panel. I have seen how to add new sections to the panel using <code>add_action( 'customize_register'...</code></p> <p>The control I want to implement is a different kind of color picker. In <a href="https://wordpress.stackexc...
[ { "answer_id": 60533, "author": "onetrickpony", "author_id": 1986, "author_profile": "https://wordpress.stackexchange.com/users/1986", "pm_score": 2, "selected": false, "text": "<p>You're never using your class. Try passing a new instance of your class to the add_control method:</p>\n\n<...
2012/07/16
[ "https://wordpress.stackexchange.com/questions/58633", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18211/" ]
I'm looking for a way to add a new kind of control to the customize *live preview* panel. I have seen how to add new sections to the panel using `add_action( 'customize_register'...` The control I want to implement is a different kind of color picker. In [a previous post](https://wordpress.stackexchange.com/questions...
Example and class for usage =========================== You can see on my current theme, how it's possible to use this. Also you can usage the class. See this [class](https://github.com/bueltge/Documentation/blob/master/inc/theme-options.php) on Github an check the [`functions.php`](https://github.com/bueltge/Document...
58,638
<p>I have a custom post type named <code>domicile</code>. Each post (domicile) has an <em>owner</em> (not the <em>author</em>). Owners are users with a custom role. I store the user id as a post meta value (<code>dmb_owner</code>) for the <code>domicile</code> post type.</p> <p>How do I sort the list table (<code>wp-a...
[ { "answer_id": 58640, "author": "bueltge", "author_id": 170, "author_profile": "https://wordpress.stackexchange.com/users/170", "pm_score": 0, "selected": false, "text": "<p>You can add the custom field <code>dmb_owner</code> to the query in backend and then you can filter about this wit...
2012/07/16
[ "https://wordpress.stackexchange.com/questions/58638", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/73/" ]
I have a custom post type named `domicile`. Each post (domicile) has an *owner* (not the *author*). Owners are users with a custom role. I store the user id as a post meta value (`dmb_owner`) for the `domicile` post type. How do I sort the list table (`wp-admin/edit.php?post_type=domicile`) by the display names of own...
An 'easy' but not very good solution is to store the user's display name as well as ID, and sort by that. Obviously an update of a user's display name would prompt an update of all the domicile that user owns. Alternatively the following is an outline (untested) of what should work. The idea is to tell WordPress to so...
58,642
<p>I wanted limited excerpt (40 words) with readmore link...I used this code below:</p> <pre><code>&lt;?php echo apply_filters('the_excerpt',get_the_excerpt().'&lt;a href="'.get_permalink().'"&gt; read more &lt;/a&gt;'); ?&gt; </code></pre> <p>any help appreciated.</p>
[ { "answer_id": 58643, "author": "bueltge", "author_id": 170, "author_profile": "https://wordpress.stackexchange.com/users/170", "pm_score": 2, "selected": false, "text": "<p>You can use the default filter for the length of <code>the_excerpt</code></p>\n\n<pre><code>// Changing excerpt le...
2012/07/16
[ "https://wordpress.stackexchange.com/questions/58642", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/16951/" ]
I wanted limited excerpt (40 words) with readmore link...I used this code below: ``` <?php echo apply_filters('the_excerpt',get_the_excerpt().'<a href="'.get_permalink().'"> read more </a>'); ?> ``` any help appreciated.
You can use the default filter for the length of `the_excerpt` ``` // Changing excerpt length function new_excerpt_length($length) { return 40; } add_filter('excerpt_length', 'new_excerpt_length'); ```
58,649
<p>I want to remove the <code>&lt;ul&gt;</code> tags from the <code>wp_nav_menu</code>. I already found different posts about it here but they don´t seem to work for me. Here is what I did:</p> <p>First I registered the menu in functions.php:</p> <pre><code>add_action('init', 'register_custom_menu'); function regist...
[ { "answer_id": 58740, "author": "Jannik Ruf", "author_id": 18217, "author_profile": "https://wordpress.stackexchange.com/users/18217", "pm_score": 0, "selected": false, "text": "<p>Since it didn't work any other way, I used jQuery to unwrap the menu.</p>\n\n<p>I put in <code>$('li.menu-i...
2012/07/16
[ "https://wordpress.stackexchange.com/questions/58649", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18217/" ]
I want to remove the `<ul>` tags from the `wp_nav_menu`. I already found different posts about it here but they don´t seem to work for me. Here is what I did: First I registered the menu in functions.php: ``` add_action('init', 'register_custom_menu'); function register_custom_menu() { register_nav_menu('main-na...
``` <?php wp_nav_menu( array( 'items_wrap' => '%3$s' ) ); ?> ``` Source <http://codex.wordpress.org/Function_Reference/wp_nav_menu#Removing_the_ul_wrap>
58,661
<p>i have a memory issue while NextgenGallery try to create the thumbnails.</p> <p>Wp-Version is 3.4.1</p> <p>Fatal error: Out of memory (allocated 29884416) (tried to allocate 2000 bytes) in /xxx/wp-content/plugins/nextgen-gallery/lib/gd.thumbnail.inc.php on line 179</p> <p>But my memory is not exceeded: <strong>PH...
[ { "answer_id": 58740, "author": "Jannik Ruf", "author_id": 18217, "author_profile": "https://wordpress.stackexchange.com/users/18217", "pm_score": 0, "selected": false, "text": "<p>Since it didn't work any other way, I used jQuery to unwrap the menu.</p>\n\n<p>I put in <code>$('li.menu-i...
2012/07/16
[ "https://wordpress.stackexchange.com/questions/58661", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/12812/" ]
i have a memory issue while NextgenGallery try to create the thumbnails. Wp-Version is 3.4.1 Fatal error: Out of memory (allocated 29884416) (tried to allocate 2000 bytes) in /xxx/wp-content/plugins/nextgen-gallery/lib/gd.thumbnail.inc.php on line 179 But my memory is not exceeded: **PHP Version : 5.2.17 / 32Bit OS ...
``` <?php wp_nav_menu( array( 'items_wrap' => '%3$s' ) ); ?> ``` Source <http://codex.wordpress.org/Function_Reference/wp_nav_menu#Removing_the_ul_wrap>
58,683
<p>I want to create a public front-end profile page with a friendly url like this format.</p> <pre><code>mysite.com/user/someusername </code></pre> <p>Any idea on how can i achieve this? I know it has something to do with rewrite rule but i have no idea on how can i do that. If you got any link or tutorial for me tha...
[ { "answer_id": 58793, "author": "bybloggers", "author_id": 6264, "author_profile": "https://wordpress.stackexchange.com/users/6264", "pm_score": 5, "selected": true, "text": "<p>There are two ways I've discovered doing this:</p>\n\n<ol>\n<li>Author Page with a custom rewrite rule</li>\n<...
2012/07/16
[ "https://wordpress.stackexchange.com/questions/58683", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/17721/" ]
I want to create a public front-end profile page with a friendly url like this format. ``` mysite.com/user/someusername ``` Any idea on how can i achieve this? I know it has something to do with rewrite rule but i have no idea on how can i do that. If you got any link or tutorial for me that will be great. Thanks!
There are two ways I've discovered doing this: 1. Author Page with a custom rewrite rule 2. A custom template files paired with a rewrite rule The first is more simple to implement, but may not work in all circumstances (one of which I'll describe soon). Custom Rewrite Rule ------------------- I found this solution...
58,688
<p>I have a file in my theme's folder called "test.php".</p> <p>If I go to www.mysite.com/wp-content/themes/my-theme/folder/test.php the theme loads which I assume is a 404 error handled by WP. If I change the file name to be test.html I can access it no problem.</p> <p>I tried adding the following code to my functio...
[ { "answer_id": 58691, "author": "Geert", "author_id": 4936, "author_profile": "https://wordpress.stackexchange.com/users/4936", "pm_score": 1, "selected": false, "text": "<p>Are you using <code>RewriteRule</code>s in your .htaccess file? You should be able to access PHP files directly th...
2012/07/16
[ "https://wordpress.stackexchange.com/questions/58688", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/14064/" ]
I have a file in my theme's folder called "test.php". If I go to www.mysite.com/wp-content/themes/my-theme/folder/test.php the theme loads which I assume is a 404 error handled by WP. If I change the file name to be test.html I can access it no problem. I tried adding the following code to my functions.php file (to a...
Assuming you use the correct URL to access the file, everything is being handled in your web server level and WP doesn't run at all, so WP based solutions like changing rewrite rules will not help you. It is most likely that there is some web server configuration that sends the 404 for any access to a php file at that...
58,735
<p>I'm writing a child theme for Genesis and trying to figure out to get the full image sizes on <strong>"Genesis - Featured Posts"</strong> widget. The widget has a check box <strong>"Show Featured Image"</strong> and "Image Size" options of following values.</p> <pre><code>thumbnail (150x150) featured-image(150x100...
[ { "answer_id": 59990, "author": "AnupRaj", "author_id": 18249, "author_profile": "https://wordpress.stackexchange.com/users/18249", "pm_score": 1, "selected": true, "text": "<p>A simple function which would add additional image size.</p>\n\n<pre><code>/*\n * add_image_size( 'post-thumbna...
2012/07/17
[ "https://wordpress.stackexchange.com/questions/58735", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18249/" ]
I'm writing a child theme for Genesis and trying to figure out to get the full image sizes on **"Genesis - Featured Posts"** widget. The widget has a check box **"Show Featured Image"** and "Image Size" options of following values. ``` thumbnail (150x150) featured-image(150x100) ``` The options have thumbnail sizes...
A simple function which would add additional image size. ``` /* * add_image_size( 'post-thumbnail', $width, $height, $crop ); * 280x254 */ add_image_size( 'additional-image-size', 800, 600, false ); ``` This function will add additional image size of width 800px and height 600px this function can be used in chil...
58,736
<p>I am new in Wordpress and what I really can't find how to do is the following: I have a new Page created from the CMS. This pages have different modules with text. Take for example this template <a href="http://www.templatemonster.com/demo/40000.html" rel="nofollow">http://www.templatemonster.com/demo/40000.html</a>...
[ { "answer_id": 59990, "author": "AnupRaj", "author_id": 18249, "author_profile": "https://wordpress.stackexchange.com/users/18249", "pm_score": 1, "selected": true, "text": "<p>A simple function which would add additional image size.</p>\n\n<pre><code>/*\n * add_image_size( 'post-thumbna...
2012/07/17
[ "https://wordpress.stackexchange.com/questions/58736", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/906/" ]
I am new in Wordpress and what I really can't find how to do is the following: I have a new Page created from the CMS. This pages have different modules with text. Take for example this template <http://www.templatemonster.com/demo/40000.html> There are three modules in the row with an icon, a heading and text. And be...
A simple function which would add additional image size. ``` /* * add_image_size( 'post-thumbnail', $width, $height, $crop ); * 280x254 */ add_image_size( 'additional-image-size', 800, 600, false ); ``` This function will add additional image size of width 800px and height 600px this function can be used in chil...
58,742
<p>How do i get Wordpress Login &amp; Forgot password forms in one light-box which can then be displayed inside pages where the user has to be logged in to see the content?</p> <p>Can i just copy some of the code in wp-login.php and then put it in a light box and alternate between the forms using anchor links as tabs ...
[ { "answer_id": 58767, "author": "Kavya Gokul", "author_id": 12357, "author_profile": "https://wordpress.stackexchange.com/users/12357", "pm_score": 0, "selected": false, "text": "<p>This plugin called SimpleModal Login works great <a href=\"http://wordpress.org/extend/plugins/simplemodal...
2012/07/17
[ "https://wordpress.stackexchange.com/questions/58742", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18218/" ]
How do i get Wordpress Login & Forgot password forms in one light-box which can then be displayed inside pages where the user has to be logged in to see the content? Can i just copy some of the code in wp-login.php and then put it in a light box and alternate between the forms using anchor links as tabs would normally...
### First you need your login form. I put this in header.php. ``` <div id="inline-form" class="page-login hidden"> <?php wp_login_form( array ( 'redirect' => site_url( $_SERVER['REQUEST_URI'] ), 'value_remember' => true ) ); ?> <a href="<?php echo esc_url( wp_login_url() ); ?>?action=register">Register</a><br/> ...
58,745
<p>I followed this tutorial for the page specific template -- <a href="http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates" rel="nofollow">http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates</a></p> <p>Created a page through wordpress admin panel - <code>Blog Page</code> URL like -- <code>...
[ { "answer_id": 58771, "author": "mrwweb", "author_id": 9844, "author_profile": "https://wordpress.stackexchange.com/users/9844", "pm_score": 3, "selected": true, "text": "<p>I think you're muddling up <a href=\"http://codex.wordpress.org/Template_Hierarchy\" rel=\"nofollow\">the Template...
2012/07/17
[ "https://wordpress.stackexchange.com/questions/58745", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/17855/" ]
I followed this tutorial for the page specific template -- <http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates> Created a page through wordpress admin panel - `Blog Page` URL like -- `http://localhost/wordpress/blog-page/` and set template to my template "Swapnesh" from the admin panel itself. Created ...
I think you're muddling up [the Template Hierarchy](http://codex.wordpress.org/Template_Hierarchy), so make sure to start by reading that. `page-blog-page.php` is for a page with the *slug* "blog-page." If you're using a page template, then you should name it something outside of the template hierarchy-reserved name s...
58,750
<p>I have a site that has a Wordpress blog section. I would like to enable Single Sign On in the site so that on logging onto my site, the WP blog also logs on on simultaneously. I have two user tables. One for the site, other for the WP part. What I did was add a curl along with the function for logging on the site's ...
[ { "answer_id": 58771, "author": "mrwweb", "author_id": 9844, "author_profile": "https://wordpress.stackexchange.com/users/9844", "pm_score": 3, "selected": true, "text": "<p>I think you're muddling up <a href=\"http://codex.wordpress.org/Template_Hierarchy\" rel=\"nofollow\">the Template...
2012/07/17
[ "https://wordpress.stackexchange.com/questions/58750", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/16357/" ]
I have a site that has a Wordpress blog section. I would like to enable Single Sign On in the site so that on logging onto my site, the WP blog also logs on on simultaneously. I have two user tables. One for the site, other for the WP part. What I did was add a curl along with the function for logging on the site's blo...
I think you're muddling up [the Template Hierarchy](http://codex.wordpress.org/Template_Hierarchy), so make sure to start by reading that. `page-blog-page.php` is for a page with the *slug* "blog-page." If you're using a page template, then you should name it something outside of the template hierarchy-reserved name s...
58,764
<p>Evening, </p> <p>I'm trying to make a simple 'login' feature for my site. I'd rather just have a dropdown box of sorts, and to login, the redirect back to the page you submitted it on. </p> <p>I've some code I found (I'm VERY new to wordpress), and it doesn't seem to be working right, when I click 'send', nothin...
[ { "answer_id": 58783, "author": "Max Yudin", "author_id": 11761, "author_profile": "https://wordpress.stackexchange.com/users/11761", "pm_score": 0, "selected": false, "text": "<p>Change this line:</p>\n\n<pre><code>&lt;form action=\"&lt;?php echo get_option('home'); ?&gt;../../wordpress...
2012/07/17
[ "https://wordpress.stackexchange.com/questions/58764", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18260/" ]
Evening, I'm trying to make a simple 'login' feature for my site. I'd rather just have a dropdown box of sorts, and to login, the redirect back to the page you submitted it on. I've some code I found (I'm VERY new to wordpress), and it doesn't seem to be working right, when I click 'send', nothing changes. The page...
It depends on where your login script is. This is my testscript (saved as ìndex.php`): ``` <html> <head> <title>Testform</title> </head> <body> <?php require_once '../wp-load.php'; var_dump($_COOKIE); if ( !( current_user_can('level_0') ) ){ wp_login_form(); } ...
58,795
<p>I am writing my first wordpress plugin which inserts a visualization widget inside a post. I am planning to use a shortcode for my plugin. I followed <a href="http://wp.tutsplus.com/tutorials/getting-started-with-wordpress-shortcodes/" rel="nofollow">an excellent tutorial about writing shortcodes</a>. But I still ha...
[ { "answer_id": 58804, "author": "Michael Hampton", "author_id": 18054, "author_profile": "https://wordpress.stackexchange.com/users/18054", "pm_score": 0, "selected": false, "text": "<p>The parameterized shortcode doesn't necessarily have to hit the database, and users can understand and...
2012/07/17
[ "https://wordpress.stackexchange.com/questions/58795", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/10828/" ]
I am writing my first wordpress plugin which inserts a visualization widget inside a post. I am planning to use a shortcode for my plugin. I followed [an excellent tutorial about writing shortcodes](http://wp.tutsplus.com/tutorials/getting-started-with-wordpress-shortcodes/). But I still have one question in mind. I ha...
It sounds like your function that your shortcode is working with has a lot of parameters that it can take. In general, I definitely think the better option is to use attributes for each parameter you want to control. As you know from that tutorial, shortcodes can have default values defined for the variables and use ...
58,814
<p>I want to get second level terms of a specific parent (first-level) term in a custom taxonomy. Sounds complicated but would be useful.</p> <pre><code>Term 1 SubTerm-1.1 SubTerm-1.2 SubTerm-1.2.1 Term 2 SubTerm-2.1 </code></pre> <p>Say, if <code>SubTerm-&gt;parent</code> is Term 1's id, then i want ...
[ { "answer_id": 58845, "author": "Richard", "author_id": 256, "author_profile": "https://wordpress.stackexchange.com/users/256", "pm_score": 4, "selected": true, "text": "<p>You can use PHP's <code>array_filter</code> to process the results of a taxonomy query function that returns its re...
2012/07/17
[ "https://wordpress.stackexchange.com/questions/58814", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/9408/" ]
I want to get second level terms of a specific parent (first-level) term in a custom taxonomy. Sounds complicated but would be useful. ``` Term 1 SubTerm-1.1 SubTerm-1.2 SubTerm-1.2.1 Term 2 SubTerm-2.1 ``` Say, if `SubTerm->parent` is Term 1's id, then i want to output SubTerm 1.1 and 1.2 but not 1....
You can use PHP's `array_filter` to process the results of a taxonomy query function that returns its results, and then display them. Something like: ``` # This returns the whole taxonomy... $whole_tax = get_terms('customtax', array('hide_empty' => 0)); $second_level = array_filter($whole_tax, function ($t) { # This...
58,818
<p>I have a baseball related website with multiple authors. I use the "Stick this post to the front page" to denote an "Editor's Pick" on an article. I would like to add a link/button to allow editor to do this from the front end. The method can either be in the article itself or in the Admin Bar. I do not really have ...
[ { "answer_id": 60094, "author": "bueltge", "author_id": 170, "author_profile": "https://wordpress.stackexchange.com/users/170", "pm_score": 3, "selected": true, "text": "<p>I think this small source code is your solution. It currently doesn't have frontend feedback for the Sticky Post ch...
2012/07/17
[ "https://wordpress.stackexchange.com/questions/58818", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/14558/" ]
I have a baseball related website with multiple authors. I use the "Stick this post to the front page" to denote an "Editor's Pick" on an article. I would like to add a link/button to allow editor to do this from the front end. The method can either be in the article itself or in the Admin Bar. I do not really have a p...
I think this small source code is your solution. It currently doesn't have frontend feedback for the Sticky Post change, but you can enhance this string, class or whatever you want in the function `fb_stick_post`. The first function adds the item in the Admin Bar and creates a new Url with a param value. Also, `on cli...
58,822
<p>The function below lists posts based on custom field.</p> <p>The result is involved in a list <code>&lt;li&gt;&lt;/li&gt;</code>. What I would like to do is count how many list items there are, then divide it into two ul's. Is there any way to split the result into two columns?</p> <p><img src="https://i.stack.imgur...
[ { "answer_id": 58827, "author": "Nate Cook", "author_id": 1313, "author_profile": "https://wordpress.stackexchange.com/users/1313", "pm_score": 0, "selected": false, "text": "<p>You'll want to look at the number of series posts and stick an end/start <code>&lt;ul&gt;</code> in the middle...
2012/07/18
[ "https://wordpress.stackexchange.com/questions/58822", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/12990/" ]
The function below lists posts based on custom field. The result is involved in a list `<li></li>`. What I would like to do is count how many list items there are, then divide it into two ul's. Is there any way to split the result into two columns? ![](https://i.stack.imgur.com/NGTaE.png) ``` function article_series...
You could do this with the [modulo](http://en.wikipedia.org/wiki/Modulo_operation) operator. ``` $posts = get_posts($args); $html = '<ul>'; $limit = 5; $i = 1; foreach ($posts as $post) { $html .= '<li>' . $post->post_title . '</li>'; if($i % $limit == 0) { $html .= '</ul><ul>'; } $i++; } $...
58,834
<p>Is there a way to dump a list of all meta keys being used by all posts belonging to a custom post type?</p> <p>I.e., a post-type named foods, each food (ham, spaghetti, chicken), can have a different meta key, which is generated dynamically. I can't know which meta keys have been added, but I'd like to be able to ...
[ { "answer_id": 58837, "author": "Tyrun", "author_id": 12648, "author_profile": "https://wordpress.stackexchange.com/users/12648", "pm_score": 1, "selected": false, "text": "<p>I believe you'd have to first do a query to gather up all the meta keys for all the custom post type into an arr...
2012/07/18
[ "https://wordpress.stackexchange.com/questions/58834", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/13545/" ]
Is there a way to dump a list of all meta keys being used by all posts belonging to a custom post type? I.e., a post-type named foods, each food (ham, spaghetti, chicken), can have a different meta key, which is generated dynamically. I can't know which meta keys have been added, but I'd like to be able to use a list...
You can use a simple query to get a distinct list of user-entered meta\_keys for a specific post type, then cache the results using the Transients API. The meta keys from this query will be those that do not start with an underscore or number. ``` function generate_foods_meta_keys(){ global $wpdb; $post_type =...
58,842
<p>How to limit the function of paging down to stop at number 10? Eg: pages: 1 2 3 4 5 6 7 8 9 10.</p> <pre><code>function kriesi_pagination($pages = '', $range = 2) { $showitems = ($range * 2)+1; global $paged; if(empty($paged)) $paged = 1; if($pages == '') { global $wp_query; $pages = $wp_query-...
[ { "answer_id": 58851, "author": "AnupRaj", "author_id": 18249, "author_profile": "https://wordpress.stackexchange.com/users/18249", "pm_score": 0, "selected": false, "text": "<p>try this</p>\n\n<pre><code>for ($i=1; $i &lt;= $pages; $i++)\n{\n if($i &gt;= 11) break;\n\n if (1 != $pages...
2012/07/18
[ "https://wordpress.stackexchange.com/questions/58842", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/12990/" ]
How to limit the function of paging down to stop at number 10? Eg: pages: 1 2 3 4 5 6 7 8 9 10. ``` function kriesi_pagination($pages = '', $range = 2) { $showitems = ($range * 2)+1; global $paged; if(empty($paged)) $paged = 1; if($pages == '') { global $wp_query; $pages = $wp_query->max_num_pages...
``` for ($i=1; $i <= min($pages,10); $i++) ```
58,843
<p>I've installed the wp_pagination plugin and it appears to be working fine <em>at the bottom of the page</em>, however, the pagination is not displaying at the top of the page. Below is the template code:</p> <pre><code>&lt;?php /* Template Name: Press */ get_header(); ?&gt; &lt;div id="primary"&gt; &lt;...
[ { "answer_id": 58851, "author": "AnupRaj", "author_id": 18249, "author_profile": "https://wordpress.stackexchange.com/users/18249", "pm_score": 0, "selected": false, "text": "<p>try this</p>\n\n<pre><code>for ($i=1; $i &lt;= $pages; $i++)\n{\n if($i &gt;= 11) break;\n\n if (1 != $pages...
2012/07/18
[ "https://wordpress.stackexchange.com/questions/58843", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/8497/" ]
I've installed the wp\_pagination plugin and it appears to be working fine *at the bottom of the page*, however, the pagination is not displaying at the top of the page. Below is the template code: ``` <?php /* Template Name: Press */ get_header(); ?> <div id="primary"> <div id="content" role="main"> ...
``` for ($i=1; $i <= min($pages,10); $i++) ```
58,844
<p>Is there a way to get the results of a loop with a filter before the code for the loop is performed in the structure of your code?</p> <p>My markup is something like this:</p> <pre><code>&lt;body&gt; &lt;div&gt; /* can I use a function to get the results from a loop performed after this point with a filter or...
[ { "answer_id": 58851, "author": "AnupRaj", "author_id": 18249, "author_profile": "https://wordpress.stackexchange.com/users/18249", "pm_score": 0, "selected": false, "text": "<p>try this</p>\n\n<pre><code>for ($i=1; $i &lt;= $pages; $i++)\n{\n if($i &gt;= 11) break;\n\n if (1 != $pages...
2012/07/18
[ "https://wordpress.stackexchange.com/questions/58844", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/31057/" ]
Is there a way to get the results of a loop with a filter before the code for the loop is performed in the structure of your code? My markup is something like this: ``` <body> <div> /* can I use a function to get the results from a loop performed after this point with a filter or hook of some sort */ </div> ...
``` for ($i=1; $i <= min($pages,10); $i++) ```
58,855
<p>I'm making a login form for my site, and I've this section:</p> <pre><code>&lt;?php if (is_user_logged_in()) { echo 'Hello, ', $user_login, '. &lt;a href=&quot;', wp_logout_url(), '&quot; title=&quot;Logout&quot;&gt;Logout&lt;/a&gt;'; } else { wp_login_form(); } </code></pre> <p>And after loggin in, it retur...
[ { "answer_id": 58851, "author": "AnupRaj", "author_id": 18249, "author_profile": "https://wordpress.stackexchange.com/users/18249", "pm_score": 0, "selected": false, "text": "<p>try this</p>\n\n<pre><code>for ($i=1; $i &lt;= $pages; $i++)\n{\n if($i &gt;= 11) break;\n\n if (1 != $pages...
2012/07/18
[ "https://wordpress.stackexchange.com/questions/58855", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18260/" ]
I'm making a login form for my site, and I've this section: ``` <?php if (is_user_logged_in()) { echo 'Hello, ', $user_login, '. <a href="', wp_logout_url(), '" title="Logout">Logout</a>'; } else { wp_login_form(); } ``` And after loggin in, it returns to the page with no indication of logging in. I suspe...
``` for ($i=1; $i <= min($pages,10); $i++) ```
58,864
<p>I am planning to use the <strong><a href="http://wordpress.org/extend/plugins/redirection/" rel="nofollow noreferrer">Redirection</a></strong> plugin to do redirects. The plugin's description states that it also enables 302 redirects, but I can't see how. There's no option as such (see screenshot below).</p> <p><im...
[ { "answer_id": 58851, "author": "AnupRaj", "author_id": 18249, "author_profile": "https://wordpress.stackexchange.com/users/18249", "pm_score": 0, "selected": false, "text": "<p>try this</p>\n\n<pre><code>for ($i=1; $i &lt;= $pages; $i++)\n{\n if($i &gt;= 11) break;\n\n if (1 != $pages...
2012/07/18
[ "https://wordpress.stackexchange.com/questions/58864", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/10691/" ]
I am planning to use the **[Redirection](http://wordpress.org/extend/plugins/redirection/)** plugin to do redirects. The plugin's description states that it also enables 302 redirects, but I can't see how. There's no option as such (see screenshot below). ![Redirections plugin screenshot](https://i.stack.imgur.com/DiV...
``` for ($i=1; $i <= min($pages,10); $i++) ```
58,878
<p>A client has requested some interesting functionality. THey have about 20 different scripts, most of which are needed by one page only. They would like an area within Wordpress's pages and custom post types to add scripts for THAT PAGE ONLY. So when that page loads, the script loads in the header or footer, NOT inli...
[ { "answer_id": 58851, "author": "AnupRaj", "author_id": 18249, "author_profile": "https://wordpress.stackexchange.com/users/18249", "pm_score": 0, "selected": false, "text": "<p>try this</p>\n\n<pre><code>for ($i=1; $i &lt;= $pages; $i++)\n{\n if($i &gt;= 11) break;\n\n if (1 != $pages...
2012/07/18
[ "https://wordpress.stackexchange.com/questions/58878", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/13727/" ]
A client has requested some interesting functionality. THey have about 20 different scripts, most of which are needed by one page only. They would like an area within Wordpress's pages and custom post types to add scripts for THAT PAGE ONLY. So when that page loads, the script loads in the header or footer, NOT inline ...
``` for ($i=1; $i <= min($pages,10); $i++) ```
58,888
<p>I have </p> <pre><code>index.php archive.php ... </code></pre> <p>When I go to domain.com, it loads index.php, which is expected. </p> <p>But, when I go <code>www.domain.com/page/2/</code>, it loads the correct posts (as in, the posts in the second page), but uses in <strong>index.php template</strong>. I want to...
[ { "answer_id": 58890, "author": "Richard", "author_id": 256, "author_profile": "https://wordpress.stackexchange.com/users/256", "pm_score": 1, "selected": false, "text": "<p><code>archive.php</code> is not used for subsequent pages of non-search, non-taxonomy, ... based subsets of conten...
2012/07/18
[ "https://wordpress.stackexchange.com/questions/58888", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/8902/" ]
I have ``` index.php archive.php ... ``` When I go to domain.com, it loads index.php, which is expected. But, when I go `www.domain.com/page/2/`, it loads the correct posts (as in, the posts in the second page), but uses in **index.php template**. I want to load the **archive.php template**. How is this achievabl...
`archive.php` is not used for subsequent pages of non-search, non-taxonomy, ... based subsets of content. I think you might be looking for `paged.php` (but that'll also be used for the first page). Alternatively add logic to `index.php` to call a different template where page number is greater than one. ***Correctio...
58,889
<p>I know my way around WP as probably an intermediate user. In the near future, I will have to integrate the design of a template from a completely different theme into a theme I'm currently using. The idea is to keep the look of the front page of one theme the same, and the use the design of another theme's regular b...
[ { "answer_id": 58892, "author": "Kavya Gokul", "author_id": 12357, "author_profile": "https://wordpress.stackexchange.com/users/12357", "pm_score": 1, "selected": false, "text": "<p>If you want to completely copy the design then you can create custom header and footer files such as <em>h...
2012/07/18
[ "https://wordpress.stackexchange.com/questions/58889", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18294/" ]
I know my way around WP as probably an intermediate user. In the near future, I will have to integrate the design of a template from a completely different theme into a theme I'm currently using. The idea is to keep the look of the front page of one theme the same, and the use the design of another theme's regular blog...
Think Twice ----------- I have to start by saying that this seems like a really odd idea. Having a front page that's totally different from the rest of the site will break a lot of user expectations and cause confusion. Is it really two completely different themes or do you just want a custom layout on the front page?...
58,897
<p>i am building a News site. I want to display 1 featured post from "prime" category for only few hours. after it should be expired or disappeared from the section.</p> <p>please have a look <a href="http://www.firstpost.com/" rel="nofollow">here</a> u can see the post on top. </p> <pre><code> &lt;div id="prime_news...
[ { "answer_id": 58892, "author": "Kavya Gokul", "author_id": 12357, "author_profile": "https://wordpress.stackexchange.com/users/12357", "pm_score": 1, "selected": false, "text": "<p>If you want to completely copy the design then you can create custom header and footer files such as <em>h...
2012/07/18
[ "https://wordpress.stackexchange.com/questions/58897", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/17703/" ]
i am building a News site. I want to display 1 featured post from "prime" category for only few hours. after it should be expired or disappeared from the section. please have a look [here](http://www.firstpost.com/) u can see the post on top. ``` <div id="prime_news" class="col-full"> <?php $the_query = new WP_Que...
Think Twice ----------- I have to start by saying that this seems like a really odd idea. Having a front page that's totally different from the rest of the site will break a lot of user expectations and cause confusion. Is it really two completely different themes or do you just want a custom layout on the front page?...
58,902
<p>I am using the Twenty Twelve theme, and the following is the code it uses to register and display the menu.</p> <p><strong>In functions.php:</strong></p> <pre><code>function twentytwelve_setup() { ... // This theme uses wp_nav_menu() in one location. register_nav_menu( 'primary', __( 'Primary Menu', ...
[ { "answer_id": 58907, "author": "helgatheviking", "author_id": 6477, "author_profile": "https://wordpress.stackexchange.com/users/6477", "pm_score": 3, "selected": true, "text": "<p>based on : <a href=\"http://wpfirstaid.com/2010/10/extend-the-wordpress-menu/\" rel=\"nofollow\">http://wp...
2012/07/18
[ "https://wordpress.stackexchange.com/questions/58902", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/10691/" ]
I am using the Twenty Twelve theme, and the following is the code it uses to register and display the menu. **In functions.php:** ``` function twentytwelve_setup() { ... // This theme uses wp_nav_menu() in one location. register_nav_menu( 'primary', __( 'Primary Menu', 'twentytwelve' ) ); ... } ad...
based on : <http://wpfirstaid.com/2010/10/extend-the-wordpress-menu/> ``` function wpa_58902($items){ $search = '<li class="search">'; $search .= '<form method="get" id="searchform" action="/">'; $search .= '<label for="s" class="assistive-text">Search</label>'; $search .= '<input type="text" class="fi...
58,911
<p>I've got a WordPress install that is serving up content via both HTTP and HTTPS. The site URL is configured as "http://www.example.com". This works for most situations - if a person requests a page at "https://www.example.com/page" the page is served up via HTTPS. </p> <p>However, the challenge that I'm facing is t...
[ { "answer_id": 226717, "author": "Jarod Thornton", "author_id": 44017, "author_profile": "https://wordpress.stackexchange.com/users/44017", "pm_score": 2, "selected": false, "text": "<p>An easy solution is to use .htaccess rules.</p>\n\n<pre><code>#Redirect HTTP to HTTPS\nRewriteCond %{H...
2012/07/18
[ "https://wordpress.stackexchange.com/questions/58911", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18304/" ]
I've got a WordPress install that is serving up content via both HTTP and HTTPS. The site URL is configured as "http://www.example.com". This works for most situations - if a person requests a page at "https://www.example.com/page" the page is served up via HTTPS. However, the challenge that I'm facing is that there ...
An easy solution is to use .htaccess rules. ``` #Redirect HTTP to HTTPS RewriteCond %{HTTPS} off RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] ```
58,916
<p>I need to get the role associated with a user -- not the "currently logged in user".</p> <p>I am using Buddypress (not that should matter to the nature of this question) and I am in the <code>bp_members()</code> loop.</p> <p>How can I retrieve the role of the user I am reporting on in the loop at any given time?</...
[ { "answer_id": 58921, "author": "fuxia", "author_id": 73, "author_profile": "https://wordpress.stackexchange.com/users/73", "pm_score": 4, "selected": false, "text": "<p>Use the user ID and <a href=\"http://codex.wordpress.org/Class_Reference/WP_User\"><code>WP_User</code></a>:</p>\n\n<p...
2012/07/18
[ "https://wordpress.stackexchange.com/questions/58916", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/17532/" ]
I need to get the role associated with a user -- not the "currently logged in user". I am using Buddypress (not that should matter to the nature of this question) and I am in the `bp_members()` loop. How can I retrieve the role of the user I am reporting on in the loop at any given time? Thanks.
Use the user ID and [`WP_User`](http://codex.wordpress.org/Class_Reference/WP_User): ``` $user = new WP_User( $user_id ); print wp_sprintf_l( '%l', $user->roles ); ``` Update ------ ``` /** * Get user roles by user ID. * * @param int $id * @return array */ function wpse_58916_user_roles_by_id( $id ) { $us...
58,924
<p>I found a superb post <a href="http://www.619cloud.com/blog/5-essential-steps-for-hosting-wordpress/" rel="nofollow noreferrer">here</a> about optimising WordPress for large installs.</p> <p>One of the steps refers to <code>lighthttpd</code> which sounds excellent but isn't currently supported by DirectAdmin. Last ...
[ { "answer_id": 58921, "author": "fuxia", "author_id": 73, "author_profile": "https://wordpress.stackexchange.com/users/73", "pm_score": 4, "selected": false, "text": "<p>Use the user ID and <a href=\"http://codex.wordpress.org/Class_Reference/WP_User\"><code>WP_User</code></a>:</p>\n\n<p...
2012/07/18
[ "https://wordpress.stackexchange.com/questions/58924", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/6344/" ]
I found a superb post [here](http://www.619cloud.com/blog/5-essential-steps-for-hosting-wordpress/) about optimising WordPress for large installs. One of the steps refers to `lighthttpd` which sounds excellent but isn't currently supported by DirectAdmin. Last time I messed about with a non-DA installation I managed t...
Use the user ID and [`WP_User`](http://codex.wordpress.org/Class_Reference/WP_User): ``` $user = new WP_User( $user_id ); print wp_sprintf_l( '%l', $user->roles ); ``` Update ------ ``` /** * Get user roles by user ID. * * @param int $id * @return array */ function wpse_58916_user_roles_by_id( $id ) { $us...
58,932
<p>My theme doesn't use the tag line, how can I remove it from the customizer?</p>
[ { "answer_id": 58933, "author": "byronyasgur", "author_id": 6169, "author_profile": "https://wordpress.stackexchange.com/users/6169", "pm_score": 2, "selected": false, "text": "<p>Accoring to <a href=\"http://ottopress.com/2012/how-to-leverage-the-theme-customizer-in-your-own-themes/\" r...
2012/07/18
[ "https://wordpress.stackexchange.com/questions/58932", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/6169/" ]
My theme doesn't use the tag line, how can I remove it from the customizer?
Late to the party but this will do the trick: ``` $wp_customize->remove_control('blogdescription'); ``` You want to remove just that control, not entire section as suggested above.
58,938
<p>I'm using Clipper, a coupon theme developed by AppThemes.com, and I'm trying to programmatically import coupons.</p> <p>The problem I'm having is each coupon needs to have a "store" added when it's uploaded.</p> <p>I can add the "store name" just fine, but I'm not able to update one of the custom fields associated...
[ { "answer_id": 60703, "author": "amit", "author_id": 17968, "author_profile": "https://wordpress.stackexchange.com/users/17968", "pm_score": 1, "selected": false, "text": "<p>Assuming this </p>\n\n<ul>\n<li><code>store</code> is custom post type.</li>\n<li><code>stores</code> is category...
2012/07/18
[ "https://wordpress.stackexchange.com/questions/58938", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18313/" ]
I'm using Clipper, a coupon theme developed by AppThemes.com, and I'm trying to programmatically import coupons. The problem I'm having is each coupon needs to have a "store" added when it's uploaded. I can add the "store name" just fine, but I'm not able to update one of the custom fields associated with the "stores...
**wp\_update\_term** does not support custom fields so you will need to use **update\_term\_meta** instead. This stores values like this: ``` update_term_meta( $term_id, $metakey, $metavalue ); ``` Your code should look something like this: ``` update_term_meta( 41, 'clpr_store_url', $url); update_term_meta( 41, '...
58,943
<p>I am trying to create a function for my functions.php file that will allow me to convert a post name into a post id. I have had a look around online and managed to find this link <a href="http://www.devdevote.com/cms/wordpress-hacks/get_id_by_post_name" rel="nofollow">http://www.devdevote.com/cms/wordpress-hacks/ge...
[ { "answer_id": 58944, "author": "fuxia", "author_id": 73, "author_profile": "https://wordpress.stackexchange.com/users/73", "pm_score": 3, "selected": true, "text": "<p>Use <a href=\"http://codex.wordpress.org/Function_Reference/get_page_by_title\" rel=\"nofollow\"><code>get_page_by_titl...
2012/07/18
[ "https://wordpress.stackexchange.com/questions/58943", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/10247/" ]
I am trying to create a function for my functions.php file that will allow me to convert a post name into a post id. I have had a look around online and managed to find this link <http://www.devdevote.com/cms/wordpress-hacks/get_id_by_post_name> which gives the following example.. ``` function get_id_by_post_name($pos...
Use [`get_page_by_title()`](http://codex.wordpress.org/Function_Reference/get_page_by_title). It works with any post type. ``` $post = get_page_by_title( $post_name, OBJECT, 'post' ); echo $post->ID; ```
58,951
<p>I am going to write my own post display thing, and I cannot find a list of all these type of functions: </p> <pre><code>the_date(); the_title(); the_excerpt(); </code></pre> <p>I'm sure there are more, but where can I find a list? </p>
[ { "answer_id": 58952, "author": "fdsa", "author_id": 8288, "author_profile": "https://wordpress.stackexchange.com/users/8288", "pm_score": 2, "selected": false, "text": "<p>Your best bet is the <a href=\"http://codex.wordpress.org/Function_Reference\" rel=\"nofollow\">Wordpress Function ...
2012/07/19
[ "https://wordpress.stackexchange.com/questions/58951", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18260/" ]
I am going to write my own post display thing, and I cannot find a list of all these type of functions: ``` the_date(); the_title(); the_excerpt(); ``` I'm sure there are more, but where can I find a list?
**#1)** A doc for a function on **[WordPress codex](http://codex.wordpress.org/)** lists all related functions at the bottom of the page. For example, [this is the doc for `the_date();`](http://codex.wordpress.org/Function_Reference/the_date) — look at the section highlighted in the screenshot below: **Click on the im...
58,967
<p>I'm currently using this to add post meta</p> <pre><code> add_post_meta($post_id, 'when', $date); </code></pre> <p>Naturally, it creates a new meta key/value combination each time.</p> <p>I want to another value to the key, so that when date is submitted again, there are now TWO dates in the "when" meta key?</...
[ { "answer_id": 58969, "author": "Brian Fegter", "author_id": 4793, "author_profile": "https://wordpress.stackexchange.com/users/4793", "pm_score": 3, "selected": true, "text": "<p>Use the following instead of add_post_meta:</p>\n\n<pre><code>update_post_meta($post_id, 'when' $date);\n</c...
2012/07/19
[ "https://wordpress.stackexchange.com/questions/58967", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/13545/" ]
I'm currently using this to add post meta ``` add_post_meta($post_id, 'when', $date); ``` Naturally, it creates a new meta key/value combination each time. I want to another value to the key, so that when date is submitted again, there are now TWO dates in the "when" meta key? Would I then be able to query the...
Use the following instead of add\_post\_meta: ``` update_post_meta($post_id, 'when' $date); ``` `add_post_meta` does just that, adds a new meta key every time, including duplicates in your case. `update_post_meta` also incorporates `add_post_meta` if a key doesn't exist, but updates an existing key. For reference:...
58,972
<p>Im looking to count how many meta keys exist within a post, because each time a specific user action happens, a new meta key is created with a date in it.</p> <p>I have this, which does not return anything (I'm looking for a number)...</p> <pre><code> ... $post_title = $row-&gt;post_title; $id = $ro...
[ { "answer_id": 58974, "author": "marctain", "author_id": 13545, "author_profile": "https://wordpress.stackexchange.com/users/13545", "pm_score": -1, "selected": false, "text": "<p>I solved this problem with some more trial and error:</p>\n\n<p>This got me the # of post meta with the corr...
2012/07/19
[ "https://wordpress.stackexchange.com/questions/58972", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/13545/" ]
Im looking to count how many meta keys exist within a post, because each time a specific user action happens, a new meta key is created with a date in it. I have this, which does not return anything (I'm looking for a number)... ``` ... $post_title = $row->post_title; $id = $row->ID; $post_count = $w...
You have a structural problem with your data. Serialized data in the database is terrible if you need to search over pieces of that serialized data. There is no reliable, efficient, and certainly no easy, SQL query to search over serialized data. "serialization" is a PHP mechanism. It isn't SQL. To the database that i...
59,007
<p>I have a site I'm putting together for a friend and I would like all new pages that are created to be the children of a set page (page id 495). I assume that I need to edit the meta-boxes.php file but not sure other than that.</p> <p>Can anyone help me with this? I'd appreciate any comments.</p> <p>Joe</p>
[ { "answer_id": 59053, "author": "TheDeadMedic", "author_id": 1685, "author_profile": "https://wordpress.stackexchange.com/users/1685", "pm_score": 1, "selected": false, "text": "<p>This hooks onto the <code>wp_insert_post_data</code> filter, and checks if the post to be inserted is both ...
2012/07/19
[ "https://wordpress.stackexchange.com/questions/59007", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18334/" ]
I have a site I'm putting together for a friend and I would like all new pages that are created to be the children of a set page (page id 495). I assume that I need to edit the meta-boxes.php file but not sure other than that. Can anyone help me with this? I'd appreciate any comments. Joe
This hooks onto the `wp_insert_post_data` filter, and checks if the post to be inserted is both a page and an auto-draft (which happens when you first create a new post/page). ``` add_filter( 'wp_insert_post_data', 'wpse_59007_set_default_page_parent' ); function wpse_59007_set_default_page_parent( $data ) { if ( ...
59,009
<p>How can I display WordPress Post Content in 3 Columns and in order using WP_Query(); ?</p> <p>For example,</p> <pre><code>&lt;div class="1column"&gt; Post-1 Post-4 &lt;/div&gt; &lt;div class="2column"&gt; Post-2 Post-5 &lt;/div&gt; &lt;div class="3column"&gt; Post-3 Post-6 &lt;/div&gt; </co...
[ { "answer_id": 59010, "author": "selva", "author_id": 15314, "author_profile": "https://wordpress.stackexchange.com/users/15314", "pm_score": 0, "selected": false, "text": "<p>Try below code...</p>\n\n<pre><code>&lt;?php\n$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;\n\...
2012/07/19
[ "https://wordpress.stackexchange.com/questions/59009", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/23344/" ]
How can I display WordPress Post Content in 3 Columns and in order using WP\_Query(); ? For example, ``` <div class="1column"> Post-1 Post-4 </div> <div class="2column"> Post-2 Post-5 </div> <div class="3column"> Post-3 Post-6 </div> ``` Any help is appreciated! Thanks.
Query the posts like you are known to it, but then get all posts and restructure them for the order you need it. Take care of setting up the global `$post` variable your own so that to ensure you template code still works. The [`array_chunk`*­Docs*](http://php.net/array_chunk) function normally comes in handy for colu...
59,020
<p>I want to make a search page, offering search functionalities by: 1) word 2) tag 3) category 4) author Can you recommend any technique, any guideline as per how to tackle this?</p>
[ { "answer_id": 59022, "author": "deadlyhifi", "author_id": 737, "author_profile": "https://wordpress.stackexchange.com/users/737", "pm_score": 3, "selected": true, "text": "<p>You'll want to add some radio buttons inside your search form. Then add a filter to your search:</p>\n\n<pre><co...
2012/07/19
[ "https://wordpress.stackexchange.com/questions/59020", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/16266/" ]
I want to make a search page, offering search functionalities by: 1) word 2) tag 3) category 4) author Can you recommend any technique, any guideline as per how to tackle this?
You'll want to add some radio buttons inside your search form. Then add a filter to your search: ``` function filter_search( $query ) { if( $query->is_search ) { if ( isset($_GET['tag']) ) // alter your search query here. } return $query; } add_filter( 'pre_get_posts' , 'filter_search' ); ``` ...
59,024
<p>Is there any way to add the <code>.html</code> extension to custom post types <strong>without plugin</strong> ?</p> <p>For posts I can use <code>/%postname.html</code> on the permalink settings</p> <p>For pages I can use: </p> <pre><code>add_action('init', 'change_page_permalink', -1); function change_page_permal...
[ { "answer_id": 59028, "author": "Michael Ecklund", "author_id": 9579, "author_profile": "https://wordpress.stackexchange.com/users/9579", "pm_score": 2, "selected": false, "text": "<p>If you would prefer a WordPress plugin to handle the work for you, check out \n<a href=\"http://wordpres...
2012/07/19
[ "https://wordpress.stackexchange.com/questions/59024", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/15704/" ]
Is there any way to add the `.html` extension to custom post types **without plugin** ? For posts I can use `/%postname.html` on the permalink settings For pages I can use: ``` add_action('init', 'change_page_permalink', -1); function change_page_permalink() { global $wp_rewrite; if ( strstr($wp_rewrite->ge...
This seem to work: Create the rewrite rules like `post-type/post-name.html`. You can use arrays to create the rules for just some set of post types instead of doing it for all of them. ``` add_action( 'rewrite_rules_array', 'rewrite_rules' ); function rewrite_rules( $rules ) { $new_rules = array(); foreach ( ...
59,037
<p>I am looking for a way to override the currently selected theme, preferably from within the wp_config.php file. I know you can override some wp_options settings in the config like </p> <pre><code>define('WP_HOME', 'http://someotherdomain.com'); </code></pre> <p>This will override the 'home' option in the wp_optio...
[ { "answer_id": 59043, "author": "TheDeadMedic", "author_id": 1685, "author_profile": "https://wordpress.stackexchange.com/users/1685", "pm_score": 4, "selected": true, "text": "<p><a href=\"http://codex.wordpress.org/Writing_a_Plugin\" rel=\"noreferrer\">Drop this in a plugin</a> &amp; a...
2012/07/19
[ "https://wordpress.stackexchange.com/questions/59037", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/9425/" ]
I am looking for a way to override the currently selected theme, preferably from within the wp\_config.php file. I know you can override some wp\_options settings in the config like ``` define('WP_HOME', 'http://someotherdomain.com'); ``` This will override the 'home' option in the wp\_options table. There is an op...
[Drop this in a plugin](http://codex.wordpress.org/Writing_a_Plugin) & activate. I should note this doesn't take into account things like child themes - it's purely for toggling which theme renders based on `SOME_FLAG`. ``` add_filter( 'stylesheet', 'switch_ma_theme' ); add_filter( 'template', 'switch_ma_theme' ); ...
59,042
<p>I have a slider in my theme. I have a setting in the options which controls whether that slider is set to "slide" or "fade". This slide/fade setting is in the jquery and of course the options setting is in the database. I presume the normal method of getting this setting is via AJAX but I thought I'd ask as I have a...
[ { "answer_id": 59046, "author": "TheDeadMedic", "author_id": 1685, "author_profile": "https://wordpress.stackexchange.com/users/1685", "pm_score": 3, "selected": true, "text": "<p>Enqueue the script as you would normally, &amp; then call the JS function right after the slider HTML output...
2012/07/19
[ "https://wordpress.stackexchange.com/questions/59042", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/6169/" ]
I have a slider in my theme. I have a setting in the options which controls whether that slider is set to "slide" or "fade". This slide/fade setting is in the jquery and of course the options setting is in the database. I presume the normal method of getting this setting is via AJAX but I thought I'd ask as I have a nu...
Enqueue the script as you would normally, & then call the JS function right after the slider HTML output (or on `wp_footer`), and pass a JSON config back to the function. ``` <!-- slider HTML --> <script type="text/javascript"> jQuery( "#my_slide" ).mySlider( <?php echo json_encode( $my_config /* array or ...
59,050
<p>With the help of a couple of users, my last two questions were highlighting a custom menu item through its ID.</p> <p>Now I'm trying to combine the code of the following two functions to make it work by Post Name:</p> <p><a href="https://wordpress.stackexchange.com/questions/58567/add-highlighting-to-new-admin-das...
[ { "answer_id": 59057, "author": "TheDeadMedic", "author_id": 1685, "author_profile": "https://wordpress.stackexchange.com/users/1685", "pm_score": 2, "selected": false, "text": "<p>There's a much easier way for setting the current menu context - the <code>parent_file</code> filter.</p>\n...
2012/07/19
[ "https://wordpress.stackexchange.com/questions/59050", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/10247/" ]
With the help of a couple of users, my last two questions were highlighting a custom menu item through its ID. Now I'm trying to combine the code of the following two functions to make it work by Post Name: [Add highlighting to new Admin Dashboard Menu Item](https://wordpress.stackexchange.com/questions/58567/add-hig...
Attention to the use of [**`get_page_by_title`**](http://codex.wordpress.org/Function_Reference/get_page_by_title) parameters. And also to the use of the [**Heredoc PHP**](http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc) syntax. ``` $the_post_title = 'The Portfolio'; add_a...
59,077
<p>I've been searching high and low for a php function to set a comments of a given postID open</p> <p>only found function to check what the comment status is </p> <pre><code>&lt;?php comments_open( $post_id ); ?&gt; </code></pre> <p>I need one to set comment would expect it to be </p> <pre><code>&lt;?php set_comme...
[ { "answer_id": 59082, "author": "Pontus Abrahamsson", "author_id": 16722, "author_profile": "https://wordpress.stackexchange.com/users/16722", "pm_score": 3, "selected": true, "text": "<p>Have you tried go to <strong>Posts</strong> and checked the box next to the title and in the dropdow...
2012/07/19
[ "https://wordpress.stackexchange.com/questions/59077", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/17478/" ]
I've been searching high and low for a php function to set a comments of a given postID open only found function to check what the comment status is ``` <?php comments_open( $post_id ); ?> ``` I need one to set comment would expect it to be ``` <?php set_comments_open( $post_id ); ?> ``` But it isnt anybody go...
Have you tried go to **Posts** and checked the box next to the title and in the dropdown **"Bulk Actions"** choose **Edit** and then **apply**, Comments and in the dropdown **"Allow"**. And also have added the screen in the post edit area on the tab in the header called **"Screen Options"** and checked the field calle...
59,080
<p>I've been researching this for a few days now and found many voting plugins - unfortunately none of them does exactly what I need, so I am trying to hack some functions/scripts that I've found by searching online.</p> <p>I'm working with this script, now: <a href="http://bavotasan.com/2011/a-better-voting-system-fo...
[ { "answer_id": 59096, "author": "fuxia", "author_id": 73, "author_profile": "https://wordpress.stackexchange.com/users/73", "pm_score": 2, "selected": false, "text": "<p>The only difference you need is the place where the IP address will be stored. Instead of a post meta use an option.</...
2012/07/19
[ "https://wordpress.stackexchange.com/questions/59080", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/17161/" ]
I've been researching this for a few days now and found many voting plugins - unfortunately none of them does exactly what I need, so I am trying to hack some functions/scripts that I've found by searching online. I'm working with this script, now: <http://bavotasan.com/2011/a-better-voting-system-for-wordpress/> I'm...
The only difference you need is the place where the IP address will be stored. Instead of a post meta use an option. So, where the script says … ``` $voter_ips = get_post_meta($postid, "voter_ips", true); ``` … use … ``` $voter_ips = get_option( "wpse_59080_voter_ips", true ); ``` … and where it updates a post m...
59,081
<p>While following <a href="https://stackoverflow.com/questions/2941251/how-to-limit-the-wordpress-tagcloud-by-date">this article</a> to get tags by date, I was wondering if I could exclude certain tags from what gets returned. The point is to have trending tags but some tags will always be there and I don't want to in...
[ { "answer_id": 59085, "author": "Pontus Abrahamsson", "author_id": 16722, "author_profile": "https://wordpress.stackexchange.com/users/16722", "pm_score": 1, "selected": false, "text": "<p>The function <code>get_the_tags</code> returns an array of objects, one object for each tag assigne...
2012/07/19
[ "https://wordpress.stackexchange.com/questions/59081", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/13349/" ]
While following [this article](https://stackoverflow.com/questions/2941251/how-to-limit-the-wordpress-tagcloud-by-date) to get tags by date, I was wondering if I could exclude certain tags from what gets returned. The point is to have trending tags but some tags will always be there and I don't want to include those on...
``` <?php $how_many_posts = 50; $exclude_these_term_ids = array( 10, 20, 35, ); $args = array( 'posts_per_page' => $how_many_posts, 'orderby' => 'date', 'order' => 'DESC', ); // get the last $how_many_posts, which we will loop over // and gather t...
59,086
<p>I am trying to send out e-mail, SMS and IM notifications to group members of this WordPress website, whenever a WordPress page in their user group has been published/updated.</p> <p>I figured using the action hook <code>'save_post'</code> would be the best solution. However, I ran into some annoying factors along t...
[ { "answer_id": 59118, "author": "Brian Fegter", "author_id": 4793, "author_profile": "https://wordpress.stackexchange.com/users/4793", "pm_score": 4, "selected": true, "text": "<p><strong>Updated:</strong></p>\n\n<p>First, you will need to return a bool value on your notifications method...
2012/07/19
[ "https://wordpress.stackexchange.com/questions/59086", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/9579/" ]
I am trying to send out e-mail, SMS and IM notifications to group members of this WordPress website, whenever a WordPress page in their user group has been published/updated. I figured using the action hook `'save_post'` would be the best solution. However, I ran into some annoying factors along the way, and believe I...
**Updated:** First, you will need to return a bool value on your notifications method so we can reliably set a marker for the message method. Then, you will need to set a $\_POST array element to pass on to the redirection filter. ``` public function save_post($post_id){ //Add a $_POST key if you syndicated succe...
59,089
<p>I'm generating my CSS dinamically in a function using a link like this</p> <pre><code>&lt;link id="www-core-css" rel="stylesheet" href="http://wordpress/myplugin/theme-css-loader.php?v=1" /&gt; </code></pre> <p>and i was wondering what approach to take. I could either point the href to a file like <code>http://wo...
[ { "answer_id": 59097, "author": "TheDeadMedic", "author_id": 1685, "author_profile": "https://wordpress.stackexchange.com/users/1685", "pm_score": 2, "selected": true, "text": "<p>This is forked from something I wrote for a similar requirement.</p>\n\n<pre><code>empty( $_GET['my-css-var'...
2012/07/19
[ "https://wordpress.stackexchange.com/questions/59089", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/13205/" ]
I'm generating my CSS dinamically in a function using a link like this ``` <link id="www-core-css" rel="stylesheet" href="http://wordpress/myplugin/theme-css-loader.php?v=1" /> ``` and i was wondering what approach to take. I could either point the href to a file like `http://wordpress/myplugin/theme-css-loader.php...
This is forked from something I wrote for a similar requirement. ``` empty( $_GET['my-css-var'] ) || add_action( 'plugins_loaded', 'wpse_59089_css' ); function wpse_59089_css() { header( 'Content-Type: text/css' ); // Aggressive caching to save future requests from the same client. $etag = '"' . md...
59,090
<p>I have a theme that automatically adds some widgets. I don't want them and so I tried to edit the Sidebar.php but it just fails and sends me to a page with message 404. Here's the code block I am trying to delete from Sidebar.php:</p> <pre><code>&lt;!-- sidebar south START --&gt; &lt;div id="southsidebar" class="si...
[ { "answer_id": 59092, "author": "Tribalpixel", "author_id": 11987, "author_profile": "https://wordpress.stackexchange.com/users/11987", "pm_score": 0, "selected": false, "text": "<pre><code>&lt;!-- sidebar south START --&gt;\n&lt;div id=\"southsidebar\" class=\"sidebar\"&gt;\n&lt;?php if...
2012/07/19
[ "https://wordpress.stackexchange.com/questions/59090", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18122/" ]
I have a theme that automatically adds some widgets. I don't want them and so I tried to edit the Sidebar.php but it just fails and sends me to a page with message 404. Here's the code block I am trying to delete from Sidebar.php: ``` <!-- sidebar south START --> <div id="southsidebar" class="sidebar"> <?php if ( !fun...
Those widgets are added because you've specified none Try adding a text widget with no content but spaces, you'll find all those hardcoded default 'widgets' dissappear You should **never** use the built in editor in WordPress though, so use FTP/Shell/VCS instead
59,120
<p>I want to create something similar to what buddypress does with member pages. For eg; <a href="http://www.example.com/members/foo" rel="nofollow noreferrer">http://www.example.com/members/foo</a></p> <p><a href="http://www.example.com/members/bar" rel="nofollow noreferrer">http://www.example.com/members/bar</a></p>...
[ { "answer_id": 59151, "author": "Deepak Mittal", "author_id": 6562, "author_profile": "https://wordpress.stackexchange.com/users/6562", "pm_score": -1, "selected": false, "text": "<p>Thanks guy. I may have not been clear with my question. I was having this exact same problem:\n<a href=\"...
2012/07/20
[ "https://wordpress.stackexchange.com/questions/59120", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/6562/" ]
I want to create something similar to what buddypress does with member pages. For eg; <http://www.example.com/members/foo> <http://www.example.com/members/bar> etc. I tried looking up the buddypress code and I see that they don't use custom post type or a custom taxonomy. It also doesn't look like they are using add...
Here is the answer. And for future references, Deepak, you need to actually post the solution as an answer. Instead, you posted your answer within your own question and then made a comment about it. Please don't do that. ``` function analytics_rewrite_add_var( $vars ) { $vars[] = 'analytic'; return $vars; } ad...
59,134
<p>I'm using a custom post type named fotograf. If it shows all photos in archive page, no problem. It finds photos in every page. But if I'm search a custom category in fotograf custom post type, then nothing found if paged>=2. Just finds the page 1. </p> <p>You can test it in my web site. <a href="http://www.onurunw...
[ { "answer_id": 59136, "author": "Milo", "author_id": 4771, "author_profile": "https://wordpress.stackexchange.com/users/4771", "pm_score": 1, "selected": false, "text": "<p>In your query you pass <code>'paged' =&gt; $paged</code>, but you never assign a value to <code>$paged</code>, so y...
2012/07/20
[ "https://wordpress.stackexchange.com/questions/59134", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18316/" ]
I'm using a custom post type named fotograf. If it shows all photos in archive page, no problem. It finds photos in every page. But if I'm search a custom category in fotograf custom post type, then nothing found if paged>=2. Just finds the page 1. You can test it in my web site. <http://www.onurunwebsitesi.com> Cli...
In your query you pass `'paged' => $paged`, but you never assign a value to `$paged`, so you are always seeing the first page of results. try defining it first: ``` $paged = (get_query_var('page')) ? get_query_var('page') : 1; $wp_query->query( array( 'post_type' =>'fotograf', 's' => $aranan, 'paged' => $paged, 'taxon...
59,137
<p>I want the wordpress CMS to manage a new type of content called Athletes. The data structure for Athlete would be as follows:</p> <pre><code>Athlete.name Athlete.date_of_birth Athlete.profile etc... </code></pre> <p>An athlete will also have a photo gallery. So in a typical relational database design, you will h...
[ { "answer_id": 59170, "author": "Jean-Patrick Smith", "author_id": 18384, "author_profile": "https://wordpress.stackexchange.com/users/18384", "pm_score": 0, "selected": false, "text": "<p>For this, I'd use <a href=\"http://podsframework.org/\" rel=\"nofollow noreferrer\">Pods CMS</a>.</...
2012/07/20
[ "https://wordpress.stackexchange.com/questions/59137", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/14576/" ]
I want the wordpress CMS to manage a new type of content called Athletes. The data structure for Athlete would be as follows: ``` Athlete.name Athlete.date_of_birth Athlete.profile etc... ``` An athlete will also have a photo gallery. So in a typical relational database design, you will have something like ``` Ath...
You want [Posts 2 Posts](http://wordpress.org/extend/plugins/posts-to-posts/) which is a phenomenal way to efficiently relate different content types in WordPress. Combine that with with some custom meta boxes with your fields and you've got a very nice, usable system that does what you want. There are [plenty](http:/...
59,147
<p>I own a wordpress installation, and Updated to 3.4.1.</p> <p>After the upgrade, I got a very strange slowdown to my wordpress.</p> <p>After all, I used the</p> <pre><code>define('SAVEQUERIES', true); </code></pre> <p>in my wp-config.php with combined with the following code in my theme footer.php</p> <pre><code...
[ { "answer_id": 59148, "author": "Damien", "author_id": 17132, "author_profile": "https://wordpress.stackexchange.com/users/17132", "pm_score": 0, "selected": false, "text": "<p>you are right ... there shouldn't be a problem with performance and your database my just need some improvement...
2012/07/20
[ "https://wordpress.stackexchange.com/questions/59147", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/7850/" ]
I own a wordpress installation, and Updated to 3.4.1. After the upgrade, I got a very strange slowdown to my wordpress. After all, I used the ``` define('SAVEQUERIES', true); ``` in my wp-config.php with combined with the following code in my theme footer.php ``` global $wpdb; echo "<pre>"; print_r($wpdb->queries...
If you've got 60,000 records, try cleaning post/page revisions; these really accumulate and cause excessively long queries. I've seen database sizes drop 90% with huge increases in performance. Run the query below in phpmyadmin or from the command line and then optimize: ``` DELETE a,b,c FROM wp_posts a LEFT JOIN wp_...
59,153
<p>I'm working to create a front end custom post type submission from. I already coded checking different tuto. But the form returned not found page upon suvmission, again not inputing any data. Please help me to find out the error if possible.</p> <pre><code>&lt;?php if (!isset($_POST['submit'])) { ?&gt; &lt;form me...
[ { "answer_id": 59197, "author": "Sagive", "author_id": 7990, "author_profile": "https://wordpress.stackexchange.com/users/7990", "pm_score": 3, "selected": true, "text": "<p>Since the meta data field is already there you should update it.<br>\nalso you should time the wp_insert_post... h...
2012/07/20
[ "https://wordpress.stackexchange.com/questions/59153", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/8096/" ]
I'm working to create a front end custom post type submission from. I already coded checking different tuto. But the form returned not found page upon suvmission, again not inputing any data. Please help me to find out the error if possible. ``` <?php if (!isset($_POST['submit'])) { ?> <form method="post" action="<?p...
Since the meta data field is already there you should update it. also you should time the wp\_insert\_post... here is the revied code try it and let me know it you encounter problems: ``` else { $title = $_POST['post_title']; $meta_box1 = $_POST['wpcf-mob_no']; $meta_box2 = $_POST['wpcf-m...
59,154
<p>I'm looking for a plugin that would allow me to create private groups for discussion that are invite only. These would be for people who have taken a workshop and want to remain in communication with their cohort afterwards. They would need to be invited/added by admin after each workshop and would not communicate...
[ { "answer_id": 59197, "author": "Sagive", "author_id": 7990, "author_profile": "https://wordpress.stackexchange.com/users/7990", "pm_score": 3, "selected": true, "text": "<p>Since the meta data field is already there you should update it.<br>\nalso you should time the wp_insert_post... h...
2012/07/20
[ "https://wordpress.stackexchange.com/questions/59154", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/11543/" ]
I'm looking for a plugin that would allow me to create private groups for discussion that are invite only. These would be for people who have taken a workshop and want to remain in communication with their cohort afterwards. They would need to be invited/added by admin after each workshop and would not communicate with...
Since the meta data field is already there you should update it. also you should time the wp\_insert\_post... here is the revied code try it and let me know it you encounter problems: ``` else { $title = $_POST['post_title']; $meta_box1 = $_POST['wpcf-mob_no']; $meta_box2 = $_POST['wpcf-m...
59,168
<p>I have been trying to rename my images on upload and only piece of code I found was the one that uses a 32char hash. </p> <pre><code>function make_filename_hash($filename) { $info = pathinfo($filename); $ext = empty($info['extension']) ? '' : '.' . $info['extension']; $name = basename($filename, $ext); ...
[ { "answer_id": 59253, "author": "fdsa", "author_id": 8288, "author_profile": "https://wordpress.stackexchange.com/users/8288", "pm_score": 0, "selected": false, "text": "<p>If you're doing them in numerical order, you could just <a href=\"http://codex.wordpress.org/Function_Reference/add...
2012/07/20
[ "https://wordpress.stackexchange.com/questions/59168", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18385/" ]
I have been trying to rename my images on upload and only piece of code I found was the one that uses a 32char hash. ``` function make_filename_hash($filename) { $info = pathinfo($filename); $ext = empty($info['extension']) ? '' : '.' . $info['extension']; $name = basename($filename, $ext); return md5($n...
no need to use a custom table, use an option, and the `add_attachment` hook: ``` function wpa59168_rename_attachment( $post_ID ) { $post = get_post( $post_ID ); $file = get_attached_file( $post_ID ); $path = pathinfo( $file ); $count = get_option( 'wpa59168_counter', 1 ); // change to $new_name ...
59,182
<p>So I uploaded a lot of similar looking photos, and uploaded a duplicate or two.</p> <p>I go into the backend to the Media panel, but alas, each row has a small thumbnail, making it time consuming to figure out which ones are the duplicates, or just to tell them apart.</p> <p>How would I make the image bigger? At t...
[ { "answer_id": 59187, "author": "Jeremy Jared", "author_id": 5339, "author_profile": "https://wordpress.stackexchange.com/users/5339", "pm_score": 0, "selected": false, "text": "<p>What your asking isn't a \"simple\" fix. If you're serious about getting larger thumbs I'd start by looking...
2012/07/21
[ "https://wordpress.stackexchange.com/questions/59182", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/736/" ]
So I uploaded a lot of similar looking photos, and uploaded a duplicate or two. I go into the backend to the Media panel, but alas, each row has a small thumbnail, making it time consuming to figure out which ones are the duplicates, or just to tell them apart. How would I make the image bigger? At the moment it is 6...
I don't see any way of hooking into this. Following the lead of `wp_get_attachment_image` takes nowhere... ``` // wp-admin/includes/class-wp-media-list-table.php // line 200 case 'icon': $attributes = 'class="column-icon media-icon"' . $style; ?> <td <?php echo $attributes ?>><?php if ( $thumb = wp_ge...
59,198
<p>I have registered a custom post type <code>'featured_post'</code>. I am looking for a way to test if the blog home page has any <code>'featured_post'</code> posts on it and if it has load a javascript file.</p> <p>The 'featured_post' posts will make a slider at the top of the blog home page. I had this working usin...
[ { "answer_id": 59199, "author": "Andre A", "author_id": 18253, "author_profile": "https://wordpress.stackexchange.com/users/18253", "pm_score": 2, "selected": true, "text": "<p>I'm at work at the moment (sorry boss), so I can't test this, but the snippet below should be the proper way of...
2012/07/21
[ "https://wordpress.stackexchange.com/questions/59198", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18398/" ]
I have registered a custom post type `'featured_post'`. I am looking for a way to test if the blog home page has any `'featured_post'` posts on it and if it has load a javascript file. The 'featured\_post' posts will make a slider at the top of the blog home page. I had this working using sticky posts but I can't work...
I'm at work at the moment (sorry boss), so I can't test this, but the snippet below should be the proper way of testing if the 'featured\_post' post type exists, and then enqueue the script if it has any posts. ``` if ( is_front_page() && post_type_exists('featured_post') ) { // We are at the front page, and the post ...
59,204
<p>As it is now, when a page that is in the nav menu is trashed, it still stays in the menu until manually remove via the nav menu editor. Is it possible to have trashed pages removed automatically?</p> <p>Thanks</p>
[ { "answer_id": 59207, "author": "Richard", "author_id": 256, "author_profile": "https://wordpress.stackexchange.com/users/256", "pm_score": 2, "selected": false, "text": "<p>You'll need a plugin which:</p>\n\n<ol>\n<li><p>Adds a method to the <code>deleted_post</code> action (taking the ...
2012/07/21
[ "https://wordpress.stackexchange.com/questions/59204", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/2830/" ]
As it is now, when a page that is in the nav menu is trashed, it still stays in the menu until manually remove via the nav menu editor. Is it possible to have trashed pages removed automatically? Thanks
Just hook the default `delete_post` handler for menus onto the trash action too: ``` add_action( 'wp_trash_post', '_wp_delete_post_menu_item' ); ``` How simple is that!
59,205
<p>Scenario: if user not login, user redirect to customize login page and redirect again to destination page after login. I don't use a function or plugin. This code to restriction page:</p> <pre><code>if (!is_user_logged_in()){ wp_redirect( get_option('home') . '?redirect_to=' . esc_url($_SERVER["HTTP_HOST"] . $_SERV...
[ { "answer_id": 59992, "author": "AnupRaj", "author_id": 18249, "author_profile": "https://wordpress.stackexchange.com/users/18249", "pm_score": 0, "selected": false, "text": "<blockquote>\n <p>Please note: wp_redirect will not be called if the page has started,\n so make sure to call i...
2012/07/21
[ "https://wordpress.stackexchange.com/questions/59205", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/16683/" ]
Scenario: if user not login, user redirect to customize login page and redirect again to destination page after login. I don't use a function or plugin. This code to restriction page: ``` if (!is_user_logged_in()){ wp_redirect( get_option('home') . '?redirect_to=' . esc_url($_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_UR...
Your snippet should work fine. First off, your custom login form may not respect `redirect_to`. `wp-login.php` does, but you'll have to send the `redirect_to` argument to the `wp-login.php` form submission as well. Show the code for your login form. You need to be careful how you use `wp_redirect`. It works by sendin...
59,227
<p>Where should a plugin ideally hook to call <code>register_sidebar();</code>?</p> <p>Will <code>init</code> do just fine?</p> <pre><code>function my_plugin_register_sidebars() { $args = array( 'name' =&gt; 'foo' 'description' =&gt; 'bar' ... ); register_sidebar( $args ); } add_ac...
[ { "answer_id": 59229, "author": "Androliyah", "author_id": 17636, "author_profile": "https://wordpress.stackexchange.com/users/17636", "pm_score": 0, "selected": false, "text": "<pre><code>add_action( 'init', 'my_plugin_register_sidebar' );\n</code></pre>\n\n<p>Edit: @Brasofilo - the ini...
2012/07/21
[ "https://wordpress.stackexchange.com/questions/59227", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/8770/" ]
Where should a plugin ideally hook to call `register_sidebar();`? Will `init` do just fine? ``` function my_plugin_register_sidebars() { $args = array( 'name' => 'foo' 'description' => 'bar' ... ); register_sidebar( $args ); } add_action( '**????**', 'my_plugin_register_sidebar' );...
Twenty Eleven and Twenty Twelve use the `widgets_init` action. Given that these themes are generally considered to use best practices for theme development, I think this hook would be ideal.
59,234
<p><a href="http://www.rarescosma.com/2010/11/add-a-class-to-wp_nav_menu-items-with-urls-included-in-the-current-url/" rel="nofollow">This solution</a> does almost what I want it to.</p> <p>Only thing is, I have my menu set up as follows:</p> <pre><code>Menu item 1 Menu item 2 Custom post type 1 Custom post typ...
[ { "answer_id": 59342, "author": "Joshua Abenazer", "author_id": 10251, "author_profile": "https://wordpress.stackexchange.com/users/10251", "pm_score": -1, "selected": false, "text": "<p>WordPress handles this by adding the <code>current_page_ancestor</code> and/or <code>current_page_par...
2012/07/21
[ "https://wordpress.stackexchange.com/questions/59234", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18408/" ]
[This solution](http://www.rarescosma.com/2010/11/add-a-class-to-wp_nav_menu-items-with-urls-included-in-the-current-url/) does almost what I want it to. Only thing is, I have my menu set up as follows: ``` Menu item 1 Menu item 2 Custom post type 1 Custom post type 2 Custom post type 3 Menu item 3 ``` Usi...
I do the following, it can be lengthy if you have many post types, feel free to edit it however: ``` /** Edit Nav Menu calsses **/ function custom_wp_nav_classes($classes, $item){ global $post; $page_blog = get_option('page_for_posts'); if(is_tax('my_taxonomy_name_here') || is_singular('my_post_type_name_...