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
162,745
<p>I aim to create a tutorial on my users for the admin area. To achieve this, I'm using the admin pointers available in WP core. My goal:</p> <p><img src="https://i.stack.imgur.com/pxhvO.jpg" alt="enter image description here"></p> <p>I am almost there. What I got so far...</p> <p>Enqueue wp-pointer scripts:</p> <...
[ { "answer_id": 162794, "author": "gmazzap", "author_id": 35541, "author_profile": "https://wordpress.stackexchange.com/users/35541", "pm_score": 5, "selected": true, "text": "<p>You are calling <code>.pointer( 'open' );</code> javascript function on all the pointers objects, so is not a ...
2014/09/27
[ "https://wordpress.stackexchange.com/questions/162745", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/24875/" ]
I aim to create a tutorial on my users for the admin area. To achieve this, I'm using the admin pointers available in WP core. My goal: ![enter image description here](https://i.stack.imgur.com/pxhvO.jpg) I am almost there. What I got so far... Enqueue wp-pointer scripts: ``` add_action( 'admin_enqueue_scripts', 'c...
You are calling `.pointer( 'open' );` javascript function on all the pointers objects, so is not a surprise that all pointers appear on same time... That said, I don't understand why do you returns all pointers (even non-active ones) from `custom_admin_pointers()` and then add an additional function to check if there ...
162,747
<p>I am filtering the content with the <code>the_content</code> filter. Everything works perfect, excerpt that my changes are applied to custom queries as well. My changes appear in the sidebar as well if the widget uses a custom query</p> <p>To counter that, I'm using <code>is_main_query()</code> to target the main q...
[ { "answer_id": 162748, "author": "Otto", "author_id": 2232, "author_profile": "https://wordpress.stackexchange.com/users/2232", "pm_score": 3, "selected": false, "text": "<p>You're using <code>is_main_query()</code> incorrectly. The global is_main_query() function returns true unless the...
2014/09/27
[ "https://wordpress.stackexchange.com/questions/162747", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/31545/" ]
I am filtering the content with the `the_content` filter. Everything works perfect, excerpt that my changes are applied to custom queries as well. My changes appear in the sidebar as well if the widget uses a custom query To counter that, I'm using `is_main_query()` to target the main query only, but it is not working...
To be honest, the function [`in_the_loop()`](https://developer.wordpress.org/reference/functions/in_the_loop/) is what you are looking for: ``` add_filter( 'the_content', 'custom_content' ); function custom_content( $content ) { if ( in_the_loop() ) { // My custom content that I add to the_content() ...
162,764
<p>I'm running multiple queries on a <code>front-page.php</code> file. They all seem to be working fine, except that I am having a hard time getting a thumbnail image.</p> <p>The code in question, on my front-page, currently looks like this:</p> <pre><code>&lt;?php $thumb_args = array( 'posts_per_page' =&gt...
[ { "answer_id": 162748, "author": "Otto", "author_id": 2232, "author_profile": "https://wordpress.stackexchange.com/users/2232", "pm_score": 3, "selected": false, "text": "<p>You're using <code>is_main_query()</code> incorrectly. The global is_main_query() function returns true unless the...
2014/09/27
[ "https://wordpress.stackexchange.com/questions/162764", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/45954/" ]
I'm running multiple queries on a `front-page.php` file. They all seem to be working fine, except that I am having a hard time getting a thumbnail image. The code in question, on my front-page, currently looks like this: ``` <?php $thumb_args = array( 'posts_per_page' => 1, 'cat' => 87 );...
To be honest, the function [`in_the_loop()`](https://developer.wordpress.org/reference/functions/in_the_loop/) is what you are looking for: ``` add_filter( 'the_content', 'custom_content' ); function custom_content( $content ) { if ( in_the_loop() ) { // My custom content that I add to the_content() ...
162,775
<p>Can anyone please help me with my problem regarding my WordPress left hand side admin menu. I want it collapsed at all times, how do I do that?</p> <p>Well, I'm creating a WP Multisite so I want that menu bar to be always collapsed at all times.</p> <p>Any help would be appreciated. Looking for code or if plugin e...
[ { "answer_id": 162780, "author": "Robert hue", "author_id": 22461, "author_profile": "https://wordpress.stackexchange.com/users/22461", "pm_score": 1, "selected": false, "text": "<p>You can try something like this.</p>\n\n<pre><code>function make_menu_unfolded() {\n print '&lt;script&...
2014/09/27
[ "https://wordpress.stackexchange.com/questions/162775", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60348/" ]
Can anyone please help me with my problem regarding my WordPress left hand side admin menu. I want it collapsed at all times, how do I do that? Well, I'm creating a WP Multisite so I want that menu bar to be always collapsed at all times. Any help would be appreciated. Looking for code or if plugin exists, should be ...
This will properly override the user settings to keep the menu collapsed for all users: ``` /** * Reset user setting to always collapse the admin menu. * * @see set_user_setting() */ function wpdocs_always_collapse_menu() { if ( 'f' != get_user_setting( 'mfold' ) ) { set_user_setting( 'mfold', 'f' ); ...
162,782
<p>I am using the $wpdb->get_var php code to get the first name and last name on the records, in the wp_usermeta table... But because the field value is stored in the same cell, I don't know how to merge it into one string. Right now I do it like this:</p> <pre><code>$_EmployeeFName = $wpdb-&gt;get_var( $wpdb-&gt;pre...
[ { "answer_id": 162785, "author": "Otto", "author_id": 2232, "author_profile": "https://wordpress.stackexchange.com/users/2232", "pm_score": 2, "selected": true, "text": "<p>Why do your own database queries? Use the WP functions to do it for you.</p>\n\n<pre><code>$empid = (int) $_REQUEST...
2014/09/28
[ "https://wordpress.stackexchange.com/questions/162782", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60351/" ]
I am using the $wpdb->get\_var php code to get the first name and last name on the records, in the wp\_usermeta table... But because the field value is stored in the same cell, I don't know how to merge it into one string. Right now I do it like this: ``` $_EmployeeFName = $wpdb->get_var( $wpdb->prepare("SELECT `meta_...
Why do your own database queries? Use the WP functions to do it for you. ``` $empid = (int) $_REQUEST['empid']; $name = get_user_meta($empid, 'first_name', true) . ' ' . get_user_meta($empid, 'last_name', true); ```
162,803
<p>In my main theme <code>functions.php</code> I have:</p> <pre><code>require_once (THEME_PATH . "/woocommerce/tw_woocommerce.php"); </code></pre> <p>So I created a woocommerce folder in my child theme folder and copied the <code>tw_woocommerce.php</code> file. However it is still the main theme <code>tw_woocommerce....
[ { "answer_id": 162797, "author": "jetlej", "author_id": 9862, "author_profile": "https://wordpress.stackexchange.com/users/9862", "pm_score": 3, "selected": true, "text": "<p>Delete DreamWeaver <em>right now</em> and do the following instead so that you can edit everything locally and se...
2014/09/28
[ "https://wordpress.stackexchange.com/questions/162803", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/11634/" ]
In my main theme `functions.php` I have: ``` require_once (THEME_PATH . "/woocommerce/tw_woocommerce.php"); ``` So I created a woocommerce folder in my child theme folder and copied the `tw_woocommerce.php` file. However it is still the main theme `tw_woocommerce.php` that is used by WP. Why and how to make it use...
Delete DreamWeaver *right now* and do the following instead so that you can edit everything locally and see changes in real-time: 1) **Install [MAMP](http://www.mamp.info/en/)** so you can run a server locally on your computer and then install Wordpress as you normally would but in a local computer folder 2) **Downlo...
162,811
<p>I'm trying to set up WordPress as a CMS. As such, I want to disable the feeds since it's mostly a secured site. I've gone through all the Settings pages but found no setting to tweak or disable the feeds. So I guess I need to write a custom function or plugin to do this. But how?</p> <p>Concerning what feeds exist,...
[ { "answer_id": 162833, "author": "Jeroen", "author_id": 24226, "author_profile": "https://wordpress.stackexchange.com/users/24226", "pm_score": 4, "selected": true, "text": "<p>As pointed out in the comments by @kaiser, your question is very similar to <a href=\"https://wordpress.stackex...
2014/09/28
[ "https://wordpress.stackexchange.com/questions/162811", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/24226/" ]
I'm trying to set up WordPress as a CMS. As such, I want to disable the feeds since it's mostly a secured site. I've gone through all the Settings pages but found no setting to tweak or disable the feeds. So I guess I need to write a custom function or plugin to do this. But how? Concerning what feeds exist, I knew of...
As pointed out in the comments by @kaiser, your question is very similar to [this question](https://wordpress.stackexchange.com/questions/119433/disable-only-the-main-feed). In fact, the *question* itself holds the answer. To disable all feeds add the following code... ``` function itsme_disable_feed() { wp_die( _...
162,816
<p>I have been through the Wordpress codex but I can't figure out how to write a filter.</p> <p>I would like to use a filter called: <code>'wpseo_sitemap_' . $filter . '_change_freq'</code>. It expects you to return one of the following values: <code>'always', 'hourly', 'daily', 'weekly', 'monthly', 'yearly', 'never'<...
[ { "answer_id": 162818, "author": "david.binda", "author_id": 14022, "author_profile": "https://wordpress.stackexchange.com/users/14022", "pm_score": 2, "selected": false, "text": "<p>To be honest, I had to actually see the source code to get the correct answer for you.</p>\n\n<p>The prob...
2014/09/28
[ "https://wordpress.stackexchange.com/questions/162816", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/40727/" ]
I have been through the Wordpress codex but I can't figure out how to write a filter. I would like to use a filter called: `'wpseo_sitemap_' . $filter . '_change_freq'`. It expects you to return one of the following values: `'always', 'hourly', 'daily', 'weekly', 'monthly', 'yearly', 'never'` I would like to set this...
To be honest, I had to actually see the source code to get the correct answer for you. The problem with this particular filter is that the `$filter` part is dynamic and thus you have to know what particular frequency you want to modify. There's a numerous of options: `homepage`, `blogpage`, `$post_type . '_archiv...
162,826
<p>I create post page from front end , and i add code for uplaod feature image. I use this code</p> <pre><code> if (!function_exists('wp_generate_attachment_metadata')){ require_once(ABSPATH . "wp-admin" . '/includes/image.php'); require_once(ABSPATH . "wp-admin" . '/includes/file.php'); ...
[ { "answer_id": 162832, "author": "adrian7", "author_id": 7171, "author_profile": "https://wordpress.stackexchange.com/users/7171", "pm_score": 0, "selected": false, "text": "<p>I guess the answer to your question is really well documented in the code you're using: </p>\n\n<pre><code> //a...
2014/09/28
[ "https://wordpress.stackexchange.com/questions/162826", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/59581/" ]
I create post page from front end , and i add code for uplaod feature image. I use this code ``` if (!function_exists('wp_generate_attachment_metadata')){ require_once(ABSPATH . "wp-admin" . '/includes/image.php'); require_once(ABSPATH . "wp-admin" . '/includes/file.php'); requi...
I edited code ``` if (!function_exists('wp_generate_attachment_metadata')){ require_once(ABSPATH . "wp-admin" . '/includes/image.php'); require_once(ABSPATH . "wp-admin" . '/includes/file.php'); require_once(ABSPATH . "wp-admin" . '/includes/media.php'); } if ($...
162,842
<p>Is there a function way that I can hide a sidebar from other admins? Meaning they can't see it so they can't edit its content but it is still there? </p> <p>I'm wanting to place my copyright, developed by footer in a sidebar via a widget so it will allow me to create more footers like this for various layouts, but ...
[ { "answer_id": 188247, "author": "Joel", "author_id": 65652, "author_profile": "https://wordpress.stackexchange.com/users/65652", "pm_score": -1, "selected": false, "text": "<p>Try the <a href=\"https://wordpress.org/plugins/adminimize/\" rel=\"nofollow\">Adminimize</a> plugin. It lets ...
2014/09/28
[ "https://wordpress.stackexchange.com/questions/162842", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/57406/" ]
Is there a function way that I can hide a sidebar from other admins? Meaning they can't see it so they can't edit its content but it is still there? I'm wanting to place my copyright, developed by footer in a sidebar via a widget so it will allow me to create more footers like this for various layouts, but I don't wa...
Here is the solution I've used which is css based. ``` global $pagenow; if (in_array($pagenow, array('widgets.php'))) { function Only_show_to_webmaster_user_things_by_css() { global $current_user; $username = $current_user->user_login; if ($username == 'Your_Username_Here') { } else { ?> <sty...
162,862
<p>In what order <code>add_action</code> hooks execute?</p> <p>i.e.</p> <pre><code>init wp_head wp_footer after_theme_setup etc... ??? ??? ??? </code></pre> <br/> <br/> <hr /> <h1>EDIT:</h1> <p>I've also posted my solution.</p>
[ { "answer_id": 162863, "author": "Robert hue", "author_id": 22461, "author_profile": "https://wordpress.stackexchange.com/users/22461", "pm_score": 5, "selected": false, "text": "<p>Here is the WordPress load chart</p>\n\n<p><img src=\"https://i.stack.imgur.com/OdZGS.png\" alt=\"WordPres...
2014/09/29
[ "https://wordpress.stackexchange.com/questions/162862", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/33667/" ]
In what order `add_action` hooks execute? i.e. ``` init wp_head wp_footer after_theme_setup etc... ??? ??? ??? ``` --- EDIT: ===== I've also posted my solution.
> > "Data! Data! Data!" he cried impatiently. "I can't make bricks without > clay." > > > [Sherlock Holmes - The Adventure of the Copper Beeches](https://en.wikisource.org/wiki/The_Adventure_of_the_Copper_Beeches) > > > So let's gather some **real data** from a vanilla WordPress 5.7.2 install and the TwentyTwelv...
162,894
<p>I want to add this code only for one post before <code>&lt;/head&gt;</code></p> <pre><code>&lt;link rel="alternate" hreflang="en-gb" href="http://abc.com"/&gt; </code></pre> <p>What code shall i use?</p>
[ { "answer_id": 162865, "author": "Johannes Pille", "author_id": 9745, "author_profile": "https://wordpress.stackexchange.com/users/9745", "pm_score": 5, "selected": true, "text": "<h2>TL;DR</h2>\n\n<p>Yes, WordPress can certainly act as a backend for a mobile app. Yes, a page can act as ...
2014/09/29
[ "https://wordpress.stackexchange.com/questions/162894", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/55140/" ]
I want to add this code only for one post before `</head>` ``` <link rel="alternate" hreflang="en-gb" href="http://abc.com"/> ``` What code shall i use?
TL;DR ----- Yes, WordPress can certainly act as a backend for a mobile app. Yes, a page can act as a rest endpoint / interface. No, a theme template is not the right territory for the logic. Write your own plugin. --- Pointers -------- > > I find it hard to believe that no one else has done this. > > > I, for ...
162,905
<p>I have a custom post type called <code>press</code>.</p> <p>I'm on the template <code>single-press.php</code></p> <p>I want to get the post titles of my custom post type named as "press". </p> <p>Here is my code,please guide me?</p> <pre><code> &lt;?php function all_posts_custom_posts( $query ) { ...
[ { "answer_id": 162907, "author": "mrwweb", "author_id": 9844, "author_profile": "https://wordpress.stackexchange.com/users/9844", "pm_score": -1, "selected": false, "text": "<p>What you describe is called a Post Type Archive and it comes baked in with WordPress. It should show up on your...
2014/09/29
[ "https://wordpress.stackexchange.com/questions/162905", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/22933/" ]
I have a custom post type called `press`. I'm on the template `single-press.php` I want to get the post titles of my custom post type named as "press". Here is my code,please guide me? ``` <?php function all_posts_custom_posts( $query ) { $post_type = $query->query_vars['post_type']; ...
As you are on, 'single-press.php' , this is single 'press' post type page. As per your question, it seems you want to display archive of all 'press' posts, along with current posts highlighted. As we are on single 'press' post page, no need to check for post type. We can directly add following loop with modification...
162,923
<p>What is the best filter for editing custom fields on a post? I am not actually editing the post content but some related fields. Would it be <code>add_filter('the_content', 'edit_custom_fields');</code>? It just seems weird to use 'the_content' here, so I am wondering if there is a more appropriate way.</p>
[ { "answer_id": 162907, "author": "mrwweb", "author_id": 9844, "author_profile": "https://wordpress.stackexchange.com/users/9844", "pm_score": -1, "selected": false, "text": "<p>What you describe is called a Post Type Archive and it comes baked in with WordPress. It should show up on your...
2014/09/29
[ "https://wordpress.stackexchange.com/questions/162923", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/35677/" ]
What is the best filter for editing custom fields on a post? I am not actually editing the post content but some related fields. Would it be `add_filter('the_content', 'edit_custom_fields');`? It just seems weird to use 'the\_content' here, so I am wondering if there is a more appropriate way.
As you are on, 'single-press.php' , this is single 'press' post type page. As per your question, it seems you want to display archive of all 'press' posts, along with current posts highlighted. As we are on single 'press' post page, no need to check for post type. We can directly add following loop with modification...
162,959
<p>I'm looking for a suggestion on how to set up the user permissions on wordpress plugin. For Example: I've Contact Form 7 plugin, when a author signing in to his account, he can see the plugin and upon clicking on it he can easily see the shortcodes. I want all author have access just the "Posts" item from wordpress ...
[ { "answer_id": 162907, "author": "mrwweb", "author_id": 9844, "author_profile": "https://wordpress.stackexchange.com/users/9844", "pm_score": -1, "selected": false, "text": "<p>What you describe is called a Post Type Archive and it comes baked in with WordPress. It should show up on your...
2014/09/30
[ "https://wordpress.stackexchange.com/questions/162959", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/51788/" ]
I'm looking for a suggestion on how to set up the user permissions on wordpress plugin. For Example: I've Contact Form 7 plugin, when a author signing in to his account, he can see the plugin and upon clicking on it he can easily see the shortcodes. I want all author have access just the "Posts" item from wordpress adm...
As you are on, 'single-press.php' , this is single 'press' post type page. As per your question, it seems you want to display archive of all 'press' posts, along with current posts highlighted. As we are on single 'press' post page, no need to check for post type. We can directly add following loop with modification...
162,974
<p>I transferred a website from localhost to a live domain. The images are not showing up and all pages link to localhost. How can I change this? Please guide. Thanks.</p>
[ { "answer_id": 162975, "author": "Zammuuz", "author_id": 40999, "author_profile": "https://wordpress.stackexchange.com/users/40999", "pm_score": 3, "selected": true, "text": "<p>You can either use the SQL query or use the Velvet Blues WordPress plugin. Via SQL </p>\n\n<pre><code>UPDATE w...
2014/09/30
[ "https://wordpress.stackexchange.com/questions/162974", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/-1/" ]
I transferred a website from localhost to a live domain. The images are not showing up and all pages link to localhost. How can I change this? Please guide. Thanks.
You can either use the SQL query or use the Velvet Blues WordPress plugin. Via SQL ``` UPDATE wp_posts SET post_content = REPLACE(post_content, 'localhost/test/', 'www.yourlivesite.com/'); ``` This will resolve the broken links and missing images issue.
162,983
<p>I have a custom loop to display posts based on a custom field. My problem is that if i have 2 posts and exclude 1 from the loop the category posts count (categories list widget with show count enable) still remains 2.</p>
[ { "answer_id": 163001, "author": "Diogo Gomes", "author_id": 60124, "author_profile": "https://wordpress.stackexchange.com/users/60124", "pm_score": 0, "selected": false, "text": "<p>If you want to exclude posts from all queries, if you are not an \"admin\", and excluding the \"single\" ...
2014/09/30
[ "https://wordpress.stackexchange.com/questions/162983", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/30792/" ]
I have a custom loop to display posts based on a custom field. My problem is that if i have 2 posts and exclude 1 from the loop the category posts count (categories list widget with show count enable) still remains 2.
Assuming you have a list containing the post IDs you want to exclude, you could start with something like (PHP 7.3): ``` function exclude_posts_from_category( array $cat_args ): array { $exclude = array(); // TODO Add post IDs to exclude. $cat_args['exclude'] = $exclude; return $cat_args; } add_filter( 'wi...
162,985
<p>Hi I want to display a specific category from a custom query in WordPress. My code works fine and it gets the latest 4 posts, but what I want now is to retrieve a specific category. My code is below thanks : </p> <pre><code>global $wpdb; $posts = $wpdb-&gt;get_results('SELECT ID, post_title AS title, post_excerpt ...
[ { "answer_id": 163001, "author": "Diogo Gomes", "author_id": 60124, "author_profile": "https://wordpress.stackexchange.com/users/60124", "pm_score": 0, "selected": false, "text": "<p>If you want to exclude posts from all queries, if you are not an \"admin\", and excluding the \"single\" ...
2014/09/30
[ "https://wordpress.stackexchange.com/questions/162985", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60454/" ]
Hi I want to display a specific category from a custom query in WordPress. My code works fine and it gets the latest 4 posts, but what I want now is to retrieve a specific category. My code is below thanks : ``` global $wpdb; $posts = $wpdb->get_results('SELECT ID, post_title AS title, post_excerpt AS excerpt FROM '...
Assuming you have a list containing the post IDs you want to exclude, you could start with something like (PHP 7.3): ``` function exclude_posts_from_category( array $cat_args ): array { $exclude = array(); // TODO Add post IDs to exclude. $cat_args['exclude'] = $exclude; return $cat_args; } add_filter( 'wi...
163,010
<p>How I can remove word "<em>Archives</em>" in head title in category page?<br> I'm using the Twenty Twelve theme and WordPress 4. </p> <pre><code>&lt;head&gt; &lt;title&gt;"name of category" Archives | "name of sites"&lt;/title&gt; &lt;/head&gt; </code></pre>
[ { "answer_id": 163023, "author": "Zammuuz", "author_id": 40999, "author_profile": "https://wordpress.stackexchange.com/users/40999", "pm_score": 4, "selected": true, "text": "<p>If you are using yoast SEO plugin then the easiest method is to remove the archive word from \"<code>titles &a...
2014/09/30
[ "https://wordpress.stackexchange.com/questions/163010", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60468/" ]
How I can remove word "*Archives*" in head title in category page? I'm using the Twenty Twelve theme and WordPress 4. ``` <head> <title>"name of category" Archives | "name of sites"</title> </head> ```
If you are using yoast SEO plugin then the easiest method is to remove the archive word from "`titles & metas-> Taxonomies->category`" find: ``` %%term_title%% Archives %%page%% %%sep%% %%sitename%% ``` replace it with: ``` %%term_title%% %%page%% %%sep%% %%sitename%% ```
163,017
<p>Hi I want to display a specific category from a custom query in WordPress. My code works fine and it gets the latest 4 posts, but what I want now is to retrieve a specific category. My code is below thanks :</p> <pre><code>global $wpdb; $posts = $wpdb-&gt;get_results('SELECT ID, post_title AS title, post_excerpt A...
[ { "answer_id": 163018, "author": "Robert hue", "author_id": 22461, "author_profile": "https://wordpress.stackexchange.com/users/22461", "pm_score": 2, "selected": false, "text": "<p>First of all, WordPress provides better ways to query with database. You should not make your query direct...
2014/09/30
[ "https://wordpress.stackexchange.com/questions/163017", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/-1/" ]
Hi I want to display a specific category from a custom query in WordPress. My code works fine and it gets the latest 4 posts, but what I want now is to retrieve a specific category. My code is below thanks : ``` global $wpdb; $posts = $wpdb->get_results('SELECT ID, post_title AS title, post_excerpt AS excerpt FROM '....
First of all, WordPress provides better ways to query with database. You should not make your query directly with `$wpdb` unless it's absolutely necessary. You should use `WP_Query` and `get_posts()` instead to receive data from WordPress database. If you want to read more about it, [read here](https://wordpress.stacke...
163,029
<p>I am working on a plugin that needs to send out an email after a form submission. </p> <p>I am using <code>wp_mail()</code> for this and it works fine. My problem is that in my code the HTML is generated by a bunch of PHP strings being added to a variable like so:</p> <pre><code>$content = $html_headers; $content ...
[ { "answer_id": 175210, "author": "ifdion", "author_id": 6383, "author_profile": "https://wordpress.stackexchange.com/users/6383", "pm_score": 3, "selected": true, "text": "<p>You should use <code>ob_get_contents()</code></p>\n\n<pre><code> ob_start();\n include('template/email-head...
2014/09/30
[ "https://wordpress.stackexchange.com/questions/163029", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/38440/" ]
I am working on a plugin that needs to send out an email after a form submission. I am using `wp_mail()` for this and it works fine. My problem is that in my code the HTML is generated by a bunch of PHP strings being added to a variable like so: ``` $content = $html_headers; $content .= '<h1>' . the_title($post_id) ...
You should use `ob_get_contents()` ``` ob_start(); include('template/email-header.php'); printf(__('<p>A very special welcome to you, %1$s. Thank you for joining %2$s!</p>', 'cell-email'), $greetings, get_bloginfo('name')); printf(__('<p> Your password is <strong style="color:orange">%s</strong> <br> P...
163,033
<p>I've followed the code based off this and everything is working perfectly -<a href="https://wordpress.stackexchange.com/questions/39500/how-to-create-a-permalink-structure-with-custom-taxonomies-and-custom-post-types">How to create a permalink structure with custom taxonomies and custom post types like base-name/par...
[ { "answer_id": 175210, "author": "ifdion", "author_id": 6383, "author_profile": "https://wordpress.stackexchange.com/users/6383", "pm_score": 3, "selected": true, "text": "<p>You should use <code>ob_get_contents()</code></p>\n\n<pre><code> ob_start();\n include('template/email-head...
2014/09/30
[ "https://wordpress.stackexchange.com/questions/163033", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60291/" ]
I've followed the code based off this and everything is working perfectly -[How to create a permalink structure with custom taxonomies and custom post types like base-name/parent-tax/child-tax/custom-post-type-name](https://wordpress.stackexchange.com/questions/39500/how-to-create-a-permalink-structure-with-custom-taxo...
You should use `ob_get_contents()` ``` ob_start(); include('template/email-header.php'); printf(__('<p>A very special welcome to you, %1$s. Thank you for joining %2$s!</p>', 'cell-email'), $greetings, get_bloginfo('name')); printf(__('<p> Your password is <strong style="color:orange">%s</strong> <br> P...
163,039
<p>It's the first time I am using the multisite option. I must be searching for the wrong terms, because I can't find the answer to what I think it's a simple problem...</p> <p>I have 3 sites.</p> <ol> <li>Group Landing site</li> <li>Group 1 site</li> <li>Group 2 site</li> </ol> <p>Essentially, Group 1 and Group 2 w...
[ { "answer_id": 163060, "author": "kanedo", "author_id": 60482, "author_profile": "https://wordpress.stackexchange.com/users/60482", "pm_score": 3, "selected": true, "text": "<p>You could use the function <a href=\"https://codex.wordpress.org/Function_Reference/switch_to_blog\" rel=\"nofo...
2014/09/30
[ "https://wordpress.stackexchange.com/questions/163039", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/30984/" ]
It's the first time I am using the multisite option. I must be searching for the wrong terms, because I can't find the answer to what I think it's a simple problem... I have 3 sites. 1. Group Landing site 2. Group 1 site 3. Group 2 site Essentially, Group 1 and Group 2 will have separate contents. However the Group ...
You could use the function [`switch_to_blog`](https://codex.wordpress.org/Function_Reference/switch_to_blog) Example: ``` switch_to_blog( $site_id ); $post = get_post( $post_id ); restore_current_blog(); ``` It should do exactly what you need. After switching you can use a custom query to get the relevant informat...
163,042
<p>I'm trying to create a local version on XAMPP of my company's WordPress website.</p> <p>All well and good except for the theme images aren't loading. (CMS images are loading)</p> <p>Looking at the image paths, I notice why they aren't loading. The root directory isn't there. It is;</p> <pre><code>http://localhost...
[ { "answer_id": 163046, "author": "Diogo Gomes", "author_id": 60124, "author_profile": "https://wordpress.stackexchange.com/users/60124", "pm_score": 1, "selected": false, "text": "<p>Probably your localhost siteurl option it's not set up right.<br>\nTry to add this on your wp-config.php ...
2014/09/30
[ "https://wordpress.stackexchange.com/questions/163042", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60475/" ]
I'm trying to create a local version on XAMPP of my company's WordPress website. All well and good except for the theme images aren't loading. (CMS images are loading) Looking at the image paths, I notice why they aren't loading. The root directory isn't there. It is; ``` http://localhost/wp-content/themes/stepladde...
Probably your localhost siteurl option it's not set up right. Try to add this on your wp-config.php file: ``` define('WP_HOME','http://localhost/stepladder'); define('WP_SITEURL','http://localhost/stepladder'); ``` If it works, then it proves that your siteurl option (on your options table) it's not correct. ho...
163,048
<p>I'm trying the next code:</p> <pre><code>$categoria = get_the_category(); $hijosCategoria = (array) get_term_children($categoria[0]-&gt;term_id, 'category'); $queryBase = array("cat"=&gt;$categoria[0]-&gt;term_id,"category__not_in"=&gt;$hijosCategoria); $objetoBase = new WP_Query($queryBase); if ($objetoBase-&gt;ha...
[ { "answer_id": 163046, "author": "Diogo Gomes", "author_id": 60124, "author_profile": "https://wordpress.stackexchange.com/users/60124", "pm_score": 1, "selected": false, "text": "<p>Probably your localhost siteurl option it's not set up right.<br>\nTry to add this on your wp-config.php ...
2014/09/30
[ "https://wordpress.stackexchange.com/questions/163048", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60178/" ]
I'm trying the next code: ``` $categoria = get_the_category(); $hijosCategoria = (array) get_term_children($categoria[0]->term_id, 'category'); $queryBase = array("cat"=>$categoria[0]->term_id,"category__not_in"=>$hijosCategoria); $objetoBase = new WP_Query($queryBase); if ($objetoBase->have_posts()){ while($objet...
Probably your localhost siteurl option it's not set up right. Try to add this on your wp-config.php file: ``` define('WP_HOME','http://localhost/stepladder'); define('WP_SITEURL','http://localhost/stepladder'); ``` If it works, then it proves that your siteurl option (on your options table) it's not correct. ho...
163,093
<p>So I have a situation on a site where I need multiple permalink structures. Now, I already know what you're going to say because literally every Google and SX result I've looked through says the same thing: <strong>Don't do this; this is a bad idea; here be dragons; etc.</strong> I've already heard all that. I've al...
[ { "answer_id": 163206, "author": "Ben Dyer", "author_id": 18466, "author_profile": "https://wordpress.stackexchange.com/users/18466", "pm_score": 2, "selected": true, "text": "<p>I think I found a solution to this with a function that's not commonly used: <code>add_permastruct()</code>.<...
2014/10/01
[ "https://wordpress.stackexchange.com/questions/163093", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18466/" ]
So I have a situation on a site where I need multiple permalink structures. Now, I already know what you're going to say because literally every Google and SX result I've looked through says the same thing: **Don't do this; this is a bad idea; here be dragons; etc.** I've already heard all that. I've already sorted out...
I think I found a solution to this with a function that's not commonly used: `add_permastruct()`. This does the trick of what I described above: ``` add_rewrite_tag('%page%','([^/]+)', 'pagename='); add_permastruct('abc','/abc/%page%/',false); add_rewrite_rule('abc/?$','index.php?page_id=6','top'); ``` The `add_re...
163,096
<p>I don't really have any code, but I'm trying to get the page views of every page on a WordPress site (and every time I hit refresh, the number of page views should increase). I would also like it so I could output that increasing number into a <strong>dashboard widget</strong>. A bit of complex code I would imagine,...
[ { "answer_id": 163099, "author": "Mayeenul Islam", "author_id": 22728, "author_profile": "https://wordpress.stackexchange.com/users/22728", "pm_score": 0, "selected": false, "text": "<p>There are many plugins out there showing the site's statistics along with the popular posts/pages with...
2014/10/01
[ "https://wordpress.stackexchange.com/questions/163096", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60503/" ]
I don't really have any code, but I'm trying to get the page views of every page on a WordPress site (and every time I hit refresh, the number of page views should increase). I would also like it so I could output that increasing number into a **dashboard widget**. A bit of complex code I would imagine, but I have no i...
You can generate page views count without any plugins. What you need to do is create a post meta key for each post (of course automatically) and increase the counter of this post meta key on each post/page load or visit. So here is the function to create a post meta key `post_views_count` for each post and calling thi...
163,130
<p>On my Wordpress-website, I have a custom post type used to display events and a page showing all events in the database. On that page, I'm creating a new WP_Query and displaying the results immediately afterwards. </p> <pre><code> $q_events = new WP_Query(array('post_type' =&gt; 'lc_events', 'orderby' =&gt; 'ID'...
[ { "answer_id": 163318, "author": "Imran Javed", "author_id": 28460, "author_profile": "https://wordpress.stackexchange.com/users/28460", "pm_score": -1, "selected": false, "text": "<p>Please try this way, may help you.</p>\n\n<pre><code> $myPageQuery= new WP_Query( 'cat=7&amp;orde...
2014/10/01
[ "https://wordpress.stackexchange.com/questions/163130", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60517/" ]
On my Wordpress-website, I have a custom post type used to display events and a page showing all events in the database. On that page, I'm creating a new WP\_Query and displaying the results immediately afterwards. ``` $q_events = new WP_Query(array('post_type' => 'lc_events', 'orderby' => 'ID')); if ($q_even...
There was nothing wrong with the query or the core Wordpress-code, but a plug-in was in the way. Thanks for all help and good advice!
163,136
<p>I am creating a custom search form which will search a custom post type called recipes. and it has a load of taxonomies. </p> <p>Now I output these taxonomy's terms into checkboxes which are grouped by the taxonomy name.</p> <p>The issue is on the input:</p> <pre><code>&lt;!-- language: lang-html --&gt; &lt;la...
[ { "answer_id": 163139, "author": "Diogo Gomes", "author_id": 60124, "author_profile": "https://wordpress.stackexchange.com/users/60124", "pm_score": 1, "selected": false, "text": "<p>Here's an option.<br>\nGive a more specific name e.g. <code>custom_search_form</code> to your submit butt...
2014/10/01
[ "https://wordpress.stackexchange.com/questions/163136", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/56609/" ]
I am creating a custom search form which will search a custom post type called recipes. and it has a load of taxonomies. Now I output these taxonomy's terms into checkboxes which are grouped by the taxonomy name. The issue is on the input: ``` <!-- language: lang-html --> <label><input type="checkbox" name="epx_...
Here's an option. Give a more specific name e.g. `custom_search_form` to your submit button: ``` (...) //First a submit button $output .= '<input type="submit" class="submit" name="custom_search_form" id="searchsubmit" value="submit" />'."\r\n"; ``` Then you can add this to your functions.php file: ``` add_actio...
163,140
<p>Is it possible to have more than one author for a WordPress plugin using the plugin comment block? I searched for it, but I think it's not possible through the default way. Is there a workaround for this?</p> <pre><code>/** * Plugin Name: Name Of The Plugin * Plugin URI: http://URI_Of_Page_Describing_Plugin_and_U...
[ { "answer_id": 163139, "author": "Diogo Gomes", "author_id": 60124, "author_profile": "https://wordpress.stackexchange.com/users/60124", "pm_score": 1, "selected": false, "text": "<p>Here's an option.<br>\nGive a more specific name e.g. <code>custom_search_form</code> to your submit butt...
2014/10/01
[ "https://wordpress.stackexchange.com/questions/163140", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/51511/" ]
Is it possible to have more than one author for a WordPress plugin using the plugin comment block? I searched for it, but I think it's not possible through the default way. Is there a workaround for this? ``` /** * Plugin Name: Name Of The Plugin * Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates * Desc...
Here's an option. Give a more specific name e.g. `custom_search_form` to your submit button: ``` (...) //First a submit button $output .= '<input type="submit" class="submit" name="custom_search_form" id="searchsubmit" value="submit" />'."\r\n"; ``` Then you can add this to your functions.php file: ``` add_actio...
163,141
<p>My setup is as follows:</p> <ul> <li>Taxonomy called 'region'</li> <li>Terms in this taxonomy like 'scotland'</li> <li>Various post types that use this single taxonomy</li> </ul> <p>I have achieved functioning pretty permalinks of the following format using the rewrite rule below:</p> <pre><code>add_rewrite_rule(...
[ { "answer_id": 163142, "author": "Rachel Carden", "author_id": 14003, "author_profile": "https://wordpress.stackexchange.com/users/14003", "pm_score": 5, "selected": true, "text": "<p>Have you tried:</p>\n\n<p><strong>The main one:</strong></p>\n\n<pre><code>add_rewrite_rule( 'region/([^...
2014/10/01
[ "https://wordpress.stackexchange.com/questions/163141", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/45120/" ]
My setup is as follows: * Taxonomy called 'region' * Terms in this taxonomy like 'scotland' * Various post types that use this single taxonomy I have achieved functioning pretty permalinks of the following format using the rewrite rule below: ``` add_rewrite_rule( 'region/([^/]+)/([^/]+)/([^/]+)/?', 'index.p...
Have you tried: **The main one:** ``` add_rewrite_rule( 'region/([^/]+)/type/([^/]+)/?', 'index.php?taxonomy=region&term=$matches[1]&post_type=$matches[2]', 'top' ); ``` **For pagination** ``` add_rewrite_rule( 'region/([^/]+)/type/([^/]+)/page/([0-9]{1,})/?', 'index.php?taxonomy=region&term=$matches[1]&post_type=...
163,147
<pre><code>&lt;form method="get" action="example.com/?category=1"&gt; &lt;input type="submit"&gt; &lt;/form&gt; </code></pre> <p><code>action</code> parameter may be any page etc. but it always redirect to homepage. If I change method to <code>POST</code> - then all fine. What is the problem here?</p>
[ { "answer_id": 163142, "author": "Rachel Carden", "author_id": 14003, "author_profile": "https://wordpress.stackexchange.com/users/14003", "pm_score": 5, "selected": true, "text": "<p>Have you tried:</p>\n\n<p><strong>The main one:</strong></p>\n\n<pre><code>add_rewrite_rule( 'region/([^...
2014/10/01
[ "https://wordpress.stackexchange.com/questions/163147", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/27488/" ]
``` <form method="get" action="example.com/?category=1"> <input type="submit"> </form> ``` `action` parameter may be any page etc. but it always redirect to homepage. If I change method to `POST` - then all fine. What is the problem here?
Have you tried: **The main one:** ``` add_rewrite_rule( 'region/([^/]+)/type/([^/]+)/?', 'index.php?taxonomy=region&term=$matches[1]&post_type=$matches[2]', 'top' ); ``` **For pagination** ``` add_rewrite_rule( 'region/([^/]+)/type/([^/]+)/page/([0-9]{1,})/?', 'index.php?taxonomy=region&term=$matches[1]&post_type=...
163,160
<p>I am having trouble calling a field and displaying its content at the frontend from a custom theme option page. This is the code I am using to display my custom theme option at the backend</p> <pre><code> add_action( 'admin_init', 'theme_options_init' ); add_action( 'admin_menu', 'theme_options_add_page' ); /*...
[ { "answer_id": 163142, "author": "Rachel Carden", "author_id": 14003, "author_profile": "https://wordpress.stackexchange.com/users/14003", "pm_score": 5, "selected": true, "text": "<p>Have you tried:</p>\n\n<p><strong>The main one:</strong></p>\n\n<pre><code>add_rewrite_rule( 'region/([^...
2014/10/01
[ "https://wordpress.stackexchange.com/questions/163160", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/54798/" ]
I am having trouble calling a field and displaying its content at the frontend from a custom theme option page. This is the code I am using to display my custom theme option at the backend ``` add_action( 'admin_init', 'theme_options_init' ); add_action( 'admin_menu', 'theme_options_add_page' ); /** Init plugin ...
Have you tried: **The main one:** ``` add_rewrite_rule( 'region/([^/]+)/type/([^/]+)/?', 'index.php?taxonomy=region&term=$matches[1]&post_type=$matches[2]', 'top' ); ``` **For pagination** ``` add_rewrite_rule( 'region/([^/]+)/type/([^/]+)/page/([0-9]{1,})/?', 'index.php?taxonomy=region&term=$matches[1]&post_type=...
163,163
<p>If my permalink structure is set to <code>/blog/%postname%/</code>, how can I retrieve a URL for my site which retrieves <code>domain.com/blog/</code>?</p> <p>With the permalink structure mentioned above, when using <code>site_url();</code>, it displays <code>domain.com/</code> when I'm looking to easily get the si...
[ { "answer_id": 163164, "author": "Robert hue", "author_id": 22461, "author_profile": "https://wordpress.stackexchange.com/users/22461", "pm_score": 0, "selected": false, "text": "<p>You will have to get link like this.</p>\n\n<pre><code>&lt;?php echo home_url( '/blog' ); ?&gt;\n</code></...
2014/10/01
[ "https://wordpress.stackexchange.com/questions/163163", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/9579/" ]
If my permalink structure is set to `/blog/%postname%/`, how can I retrieve a URL for my site which retrieves `domain.com/blog/`? With the permalink structure mentioned above, when using `site_url();`, it displays `domain.com/` when I'm looking to easily get the site's URL including the front base. Maybe I'm unclear...
You can get the value of `front` in the global `$wp_rewrite`: ``` global $wp_rewrite; echo $wp_rewrite->front; // or echo home_url( $wp_rewrite->front ); ``` Though that is probably of limited use, as the front base isn't necessarily an existing page, and may 404 in many cases. If you're using that value to prepend ...
163,176
<p>I have my page template pulling one specific category &amp; pulling the featured image &amp; title into 3 different columns on my site. The problem is they all pull the CSS class .proj-left how can I get my page to pull the featured image, title, &amp; use the specific column CSS class that should be assigned to it?...
[ { "answer_id": 163179, "author": "Howdy_McGee", "author_id": 7355, "author_profile": "https://wordpress.stackexchange.com/users/7355", "pm_score": 0, "selected": false, "text": "<p>You could do this in a few ways, below I've laid out two.</p>\n\n<p><strong>Method 1: Modulus</strong></p>\...
2014/10/01
[ "https://wordpress.stackexchange.com/questions/163176", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/9112/" ]
I have my page template pulling one specific category & pulling the featured image & title into 3 different columns on my site. The problem is they all pull the CSS class .proj-left how can I get my page to pull the featured image, title, & use the specific column CSS class that should be assigned to it? This is my p...
First of all, never use [`query_posts`](http://codex.wordpress.org/Function_Reference/query_posts) > > **Note:** This function isn't meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query\_posts() is overly simplistic and problematic way to ...
163,184
<p>I'm trying to insert content after the <code>&lt;body&gt;</code> tag using my plugin but the code I have is duplicating the <code>&lt;body&gt;</code> content.</p> <p>My code is at <a href="http://pastebin.com/rhDX8gsm" rel="nofollow">http://pastebin.com/rhDX8gsm</a> (it's quite long) and the demo URL is <a href="ht...
[ { "answer_id": 163235, "author": "Hasin Hayder", "author_id": 12927, "author_profile": "https://wordpress.stackexchange.com/users/12927", "pm_score": 1, "selected": false, "text": "<p>Add a new filter expression immediately after the <code>&lt;body&gt;</code> tag. Like the following</p>\...
2014/10/01
[ "https://wordpress.stackexchange.com/questions/163184", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/33936/" ]
I'm trying to insert content after the `<body>` tag using my plugin but the code I have is duplicating the `<body>` content. My code is at <http://pastebin.com/rhDX8gsm> (it's quite long) and the demo URL is <http://bit.ly/1mRwyKY> ``` function somefunction() { if(!is_admin()){ global $something; ...
Found the issue, wasn't the code but the actual IF elses, I had moved the panel it's built on from SMOF to Redux but SMOF gives the input a 0 if set to x, but redux leaves it blank, so I was basically checking if the input was 0 and it was failing, hence no content being sent. tip for future, read the documentation a ...
163,191
<p>I'm new to WP programming and I am having trouble with what would be a simple problem in other environments.</p> <p>I created a page (cdl-manual) using the normal WP admin UI. Then I added some functions to the theme functions.php file so I could use shortcodes for the page content. The functions look for a query p...
[ { "answer_id": 163218, "author": "Mark Kaplun", "author_id": 23970, "author_profile": "https://wordpress.stackexchange.com/users/23970", "pm_score": 1, "selected": true, "text": "<p>The reason you are getting a 404 is that the rewrite rule do not change the request URL as reported sin <c...
2014/10/01
[ "https://wordpress.stackexchange.com/questions/163191", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60393/" ]
I'm new to WP programming and I am having trouble with what would be a simple problem in other environments. I created a page (cdl-manual) using the normal WP admin UI. Then I added some functions to the theme functions.php file so I could use shortcodes for the page content. The functions look for a query parameter (...
The reason you are getting a 404 is that the rewrite rule do not change the request URL as reported sin `$_SERVER[REQUEST_URI]` variable of PHP, and wordpress parses that variable when deciding what content is request and since there is no such page /cdl-manual/arizona/ it displays a 404. What you need is a wordpress ...
163,205
<p>I have two plugins - one is the "primary" plugin called "SmartPost" and I'm trying to extend it with another plugin called "SmartPost E-mails". So, in other words, "SmartPost E-mails" extends and depends on "SmartPost" to exist and load before the e-mails plugin does.</p> <p>Within the SmartPost plugin, I have the ...
[ { "answer_id": 163218, "author": "Mark Kaplun", "author_id": 23970, "author_profile": "https://wordpress.stackexchange.com/users/23970", "pm_score": 1, "selected": true, "text": "<p>The reason you are getting a 404 is that the rewrite rule do not change the request URL as reported sin <c...
2014/10/01
[ "https://wordpress.stackexchange.com/questions/163205", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/50444/" ]
I have two plugins - one is the "primary" plugin called "SmartPost" and I'm trying to extend it with another plugin called "SmartPost E-mails". So, in other words, "SmartPost E-mails" extends and depends on "SmartPost" to exist and load before the e-mails plugin does. Within the SmartPost plugin, I have the following ...
The reason you are getting a 404 is that the rewrite rule do not change the request URL as reported sin `$_SERVER[REQUEST_URI]` variable of PHP, and wordpress parses that variable when deciding what content is request and since there is no such page /cdl-manual/arizona/ it displays a 404. What you need is a wordpress ...
163,219
<p>I cannot figure out why my <code>WP_Query</code> always displays all my published posts regardless of what I put in the arguments.</p> <pre><code>&lt;?php $args = array('numberposts' =&gt; 1, 'meta_key' =&gt; 'display', 'meta_value' =&gt; 'about' ); $about_prev...
[ { "answer_id": 163221, "author": "Robert hue", "author_id": 22461, "author_profile": "https://wordpress.stackexchange.com/users/22461", "pm_score": 2, "selected": false, "text": "<p>There is no parameter for <code>numberposts</code>. Use <code>posts_per_page</code> instead. So your code ...
2014/10/02
[ "https://wordpress.stackexchange.com/questions/163219", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60559/" ]
I cannot figure out why my `WP_Query` always displays all my published posts regardless of what I put in the arguments. ``` <?php $args = array('numberposts' => 1, 'meta_key' => 'display', 'meta_value' => 'about' ); $about_preview_query = new WP_Query($args); ...
There is no parameter for `numberposts`. Use `posts_per_page` instead. So your code will become... ``` <?php $args = array( 'posts_per_page' => 1, 'meta_key' => 'display', 'meta_value' => 'about' ); $about_preview_query = new WP_Query($args); if ( $about_preview_query->have_...
163,223
<p>Currently I'm using <code>wp-optimize</code> to remove all trashed posts, trashed comments, draft posts </p> <p>However, this plugin sometimes not working and more important, it does not delete any trashed items from custom post type which I've from other plugins or built-in from theme. So is there any way or plugi...
[ { "answer_id": 163229, "author": "Daniel Garcia Sanchez", "author_id": 59493, "author_profile": "https://wordpress.stackexchange.com/users/59493", "pm_score": 2, "selected": false, "text": "<p>You can use, in your wp-config.php:</p>\n\n<pre><code>define('EMPTY_TRASH_DAYS', 2 );\n</code><...
2014/10/02
[ "https://wordpress.stackexchange.com/questions/163223", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60560/" ]
Currently I'm using `wp-optimize` to remove all trashed posts, trashed comments, draft posts However, this plugin sometimes not working and more important, it does not delete any trashed items from custom post type which I've from other plugins or built-in from theme. So is there any way or plugin that help me to ach...
You can use, in your wp-config.php: ``` define('EMPTY_TRASH_DAYS', 2 ); ``` The example above will delete trashed posts (of all types) after 2 days.
163,236
<p>The current file upload size limit is 128MB. I want to reduce this to 1MB. I do not have access to php.ini file. I do have access to .htaccess and I could <a href="http://wp-photographers.com/how-to-increase-media-file-upload-size-wordpress/" rel="nofollow noreferrer">use this solution</a>.</p> <p>But why isn't th...
[ { "answer_id": 163288, "author": "Nicolai Grossherr", "author_id": 22534, "author_profile": "https://wordpress.stackexchange.com/users/22534", "pm_score": 1, "selected": false, "text": "<p>You can restrict the file size via the <a href=\"http://codex.wordpress.org/Plugin_API/Filter_Refer...
2014/10/02
[ "https://wordpress.stackexchange.com/questions/163236", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/1447/" ]
The current file upload size limit is 128MB. I want to reduce this to 1MB. I do not have access to php.ini file. I do have access to .htaccess and I could [use this solution](http://wp-photographers.com/how-to-increase-media-file-upload-size-wordpress/). But why isn't there a method for doing this in the `functions.p...
Absolutely, you can simply hook into `upload_size_limit` and set a maximum filesize: ``` // Change the upload size to 1MB add_filter( 'upload_size_limit', 'wpse_163236_change_upload_size' ); function wpse_163236_change_upload_size() { return 1000 * 1024; } ```
163,246
<p>I have two roles.</p> <p>A: The user sends a post for moderation</p> <p>B: The user publishes posts without moderation </p> <p>For new users the role of A. How do I do if I approve of his first post, the role is changed to B?</p>
[ { "answer_id": 163251, "author": "Diogo Gomes", "author_id": 60124, "author_profile": "https://wordpress.stackexchange.com/users/60124", "pm_score": 1, "selected": false, "text": "<p>From the <a href=\"http://codex.wordpress.org/Post_Status_Transitions\" rel=\"nofollow\">Codex Post_Statu...
2014/10/02
[ "https://wordpress.stackexchange.com/questions/163246", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60574/" ]
I have two roles. A: The user sends a post for moderation B: The user publishes posts without moderation For new users the role of A. How do I do if I approve of his first post, the role is changed to B?
You can attach code to change role when post status is changing from "pending" to "published" see documentation: <http://codex.wordpress.org/Post_Status_Transitions> Then, if user has role "contributor" you can change this to "author": ``` add_action( 'pending_to_publish'. 'my_function', 10, 1 ); function my_f...
163,250
<p>I have a page that is assigned as the "Blog". What I'd like to allow is the user to add content to this page then display it before the posts show up on <code>index.php</code>. I thought I used to be able to do it using this method:</p> <pre><code>&lt;?php $blog = get_option('page_for_posts'); echo apply_...
[ { "answer_id": 163257, "author": "Nicolai Grossherr", "author_id": 22534, "author_profile": "https://wordpress.stackexchange.com/users/22534", "pm_score": 5, "selected": true, "text": "<p>You are using <a href=\"http://codex.wordpress.org/Function_Reference/get_the_content\" rel=\"norefe...
2014/10/02
[ "https://wordpress.stackexchange.com/questions/163250", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/7355/" ]
I have a page that is assigned as the "Blog". What I'd like to allow is the user to add content to this page then display it before the posts show up on `index.php`. I thought I used to be able to do it using this method: ``` <?php $blog = get_option('page_for_posts'); echo apply_filters('the_content', get_th...
You are using [`get_the_content()`](http://codex.wordpress.org/Function_Reference/get_the_content) wrong, it can't take a ID, which is what `get_option('page_for_posts')` does return, and generally gets the content of the current post inside the loop, in which it has to be used. To get the actual content of that page ...
163,279
<p>I am new to wordpress but I was trying to add custom fields to certain posts but I don't want to manually add every time. I saw there is a custom post type class that you can specify but I didn't find any related info when I searched. Essentially I want to add metadata so that I can add search functionality on posts...
[ { "answer_id": 163257, "author": "Nicolai Grossherr", "author_id": 22534, "author_profile": "https://wordpress.stackexchange.com/users/22534", "pm_score": 5, "selected": true, "text": "<p>You are using <a href=\"http://codex.wordpress.org/Function_Reference/get_the_content\" rel=\"norefe...
2014/10/02
[ "https://wordpress.stackexchange.com/questions/163279", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60587/" ]
I am new to wordpress but I was trying to add custom fields to certain posts but I don't want to manually add every time. I saw there is a custom post type class that you can specify but I didn't find any related info when I searched. Essentially I want to add metadata so that I can add search functionality on posts. i...
You are using [`get_the_content()`](http://codex.wordpress.org/Function_Reference/get_the_content) wrong, it can't take a ID, which is what `get_option('page_for_posts')` does return, and generally gets the content of the current post inside the loop, in which it has to be used. To get the actual content of that page ...
163,282
<p>I have been running domain.co.za, but recently purchased domain.com. Both domains now point to the same Wordpress site. On domain.com pages all the links point to domain.co.za and on domain.co.za all the links point to domain.com, so it flip-flops between the two domains.</p> <p>I am wanting both domain.co.za and d...
[ { "answer_id": 163257, "author": "Nicolai Grossherr", "author_id": 22534, "author_profile": "https://wordpress.stackexchange.com/users/22534", "pm_score": 5, "selected": true, "text": "<p>You are using <a href=\"http://codex.wordpress.org/Function_Reference/get_the_content\" rel=\"norefe...
2014/10/02
[ "https://wordpress.stackexchange.com/questions/163282", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/32682/" ]
I have been running domain.co.za, but recently purchased domain.com. Both domains now point to the same Wordpress site. On domain.com pages all the links point to domain.co.za and on domain.co.za all the links point to domain.com, so it flip-flops between the two domains. I am wanting both domain.co.za and domain.com ...
You are using [`get_the_content()`](http://codex.wordpress.org/Function_Reference/get_the_content) wrong, it can't take a ID, which is what `get_option('page_for_posts')` does return, and generally gets the content of the current post inside the loop, in which it has to be used. To get the actual content of that page ...
163,286
<p>I am developing a Wordpress plugin in an object oriented way, and I would like to read data from the wordpress database using the global $wpdb variable.</p> <p>The global $wpdb variable is called from within one specific Class method. The Class is defined in the plugin editor but the object in itself is instanciate...
[ { "answer_id": 163296, "author": "Justin Bell", "author_id": 60176, "author_profile": "https://wordpress.stackexchange.com/users/60176", "pm_score": 3, "selected": true, "text": "<p>I think the problem might lie in:</p>\n\n<pre><code>$wpdbinfo = $wpdb-&gt;get_results(\"SELECT * FROM bo_m...
2014/10/02
[ "https://wordpress.stackexchange.com/questions/163286", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/54952/" ]
I am developing a Wordpress plugin in an object oriented way, and I would like to read data from the wordpress database using the global $wpdb variable. The global $wpdb variable is called from within one specific Class method. The Class is defined in the plugin editor but the object in itself is instanciated in the h...
I think the problem might lie in: ``` $wpdbinfo = $wpdb->get_results("SELECT * FROM bo_mytable WHERE id=3"); ``` `$wpdb->get_results()` returns an array of objects, yet you are referencing a property on `$wpdbinfo` (`->nameinfo`). You'll either want to loop through the `$wpdbinfo` array, or if you're certain you'll ...
163,292
<p>I'm developing a login plugin and need to test the login form that pops up after a session has expired. </p> <p>I would like to see the popup appear on my request. Any hack is fine. Ideally some little javascript to run from the console.</p>
[ { "answer_id": 163299, "author": "Ando", "author_id": 60592, "author_profile": "https://wordpress.stackexchange.com/users/60592", "pm_score": 3, "selected": false, "text": "<p>I've discovered the following stuff. </p>\n\n<p>This kind of login is called internally <em>Interim</em>. It wor...
2014/10/02
[ "https://wordpress.stackexchange.com/questions/163292", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60592/" ]
I'm developing a login plugin and need to test the login form that pops up after a session has expired. I would like to see the popup appear on my request. Any hack is fine. Ideally some little javascript to run from the console.
I've discovered the following stuff. This kind of login is called internally *Interim*. It works thanks to the continuous polling offered by the *Heartbeat API*. The prefix of the expired session functionality is *wp-auth-check* and the important bit for me was a little script at */wp-includes/js/wp-auth-check.js*. ...
163,293
<p>I am using WordPress with MU activated. I found a function <a href="http://codex.wordpress.org/WPMU_Functions/get_current_site" rel="noreferrer">here</a> that supposed to return an object with the current side ID. But it's returning 1 for all websites.</p> <pre><code>&lt;?php get_current_site(); ?&gt; </code></pre>...
[ { "answer_id": 163294, "author": "Sven", "author_id": 32946, "author_profile": "https://wordpress.stackexchange.com/users/32946", "pm_score": 4, "selected": true, "text": "<p>You're right, <code>get_current_site()-&gt;blog_id</code> will return 1, as it refers to the network.</p>\n\n<p>T...
2014/10/02
[ "https://wordpress.stackexchange.com/questions/163293", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/30984/" ]
I am using WordPress with MU activated. I found a function [here](http://codex.wordpress.org/WPMU_Functions/get_current_site) that supposed to return an object with the current side ID. But it's returning 1 for all websites. ``` <?php get_current_site(); ?> ```
You're right, `get_current_site()->blog_id` will return 1, as it refers to the network. To get the current site (blog) ID you can go like this: ``` <?php echo get_current_blog_id(); ?> ``` Moreover you can get the current site (blog) details like this: ``` <?php var_dump(get_blog_details()->blog_id); ?> ```
163,301
<h3>Context</h3> <p>I built a child theme based on Twenty Thirteen which works quite well. After updating the parent theme to version 1.3, I noticed strange behavior with the styling which was caused by a cached parent theme's <code>style.css</code>.</p> <p>Here is the content of my child theme's <code>style.css</cod...
[ { "answer_id": 163366, "author": "Otto", "author_id": 2232, "author_profile": "https://wordpress.stackexchange.com/users/2232", "pm_score": 4, "selected": false, "text": "<p>You don't have to use @import. It's best not to, actually. Using an enqueued approach is probably better all aroun...
2014/10/03
[ "https://wordpress.stackexchange.com/questions/163301", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60581/" ]
### Context I built a child theme based on Twenty Thirteen which works quite well. After updating the parent theme to version 1.3, I noticed strange behavior with the styling which was caused by a cached parent theme's `style.css`. Here is the content of my child theme's `style.css` (omitting headers) ``` /* =Import...
My [previous answer](https://wordpress.stackexchange.com/a/163624/60581) is overly complicated and potentially doesn't respect the parent theme's dependency chain (see note in other answer). Here's another much simpler take that should work much better: ``` function use_parent_theme_stylesheet() { // Use the pare...
163,324
<p>At the moment, the audio shortcode only allows four attributes, <code>src</code>, <code>loop</code>, <code>autoplay</code> and <code>preload</code>. When you upload an audio file however, it comes with pretty useful meta data such as the album art, artist, year and so on which would be great if it could be displayed...
[ { "answer_id": 165221, "author": "realloc", "author_id": 6972, "author_profile": "https://wordpress.stackexchange.com/users/6972", "pm_score": 1, "selected": false, "text": "<p>I would use the filter <a href=\"https://core.trac.wordpress.org/browser/tags/4.0/src/wp-includes/media.php#L16...
2014/10/03
[ "https://wordpress.stackexchange.com/questions/163324", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18937/" ]
At the moment, the audio shortcode only allows four attributes, `src`, `loop`, `autoplay` and `preload`. When you upload an audio file however, it comes with pretty useful meta data such as the album art, artist, year and so on which would be great if it could be displayed as well. I've been looking for a way to extend...
I would use the filter [wp\_audio\_shortcode](https://core.trac.wordpress.org/browser/tags/4.0/src/wp-includes/media.php#L1641): ``` /** * Filter the audio shortcode output. * * @since 3.6.0 * * @param string $html Audio shortcode HTML output. * @param array $atts Array of audio shortcode attributes. * @...
163,327
<p>I have this URL: <em>www.example.com/dog-to-cat</em><br> I have this Title: "Dog-to-Cat"</p> <p>In the post/page I would like to insert 2 images, <em>dog.jpg</em> and <em>cat.jpg</em><br> Also, in the text I would like to use the words "Dog" and "Cat". </p> <p>Can someone help here - I need to extract first word i...
[ { "answer_id": 163355, "author": "Rvervuurt", "author_id": 48421, "author_profile": "https://wordpress.stackexchange.com/users/48421", "pm_score": 0, "selected": false, "text": "<p>I don't think you can do this by using shortcodes, but of course you can create your own shortcode and put ...
2014/10/03
[ "https://wordpress.stackexchange.com/questions/163327", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60605/" ]
I have this URL: *www.example.com/dog-to-cat* I have this Title: "Dog-to-Cat" In the post/page I would like to insert 2 images, *dog.jpg* and *cat.jpg* Also, in the text I would like to use the words "Dog" and "Cat". Can someone help here - I need to extract first word in URL after "/" (dog) and second word af...
``` <?php function url_fetcher(){ $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVE...
163,332
<p>I want to display product assigned terms, wrapped in link/anchor MarkUp, in my sidebar on a page as a widget. I am not getting the correct tag URL. Code returns visited product URL instead of listed tags URL.</p> <p>Here is the problematic part of the code. What is the correct use of <code>get_the_terms()</code>?</...
[ { "answer_id": 163775, "author": "pendjer", "author_id": 37464, "author_profile": "https://wordpress.stackexchange.com/users/37464", "pm_score": 0, "selected": false, "text": "<p>Thanks to Mark, I solve this successfully.</p>\n\n<p>Update: Thanks to Kaiser part of the code has been updat...
2014/10/03
[ "https://wordpress.stackexchange.com/questions/163332", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/37464/" ]
I want to display product assigned terms, wrapped in link/anchor MarkUp, in my sidebar on a page as a widget. I am not getting the correct tag URL. Code returns visited product URL instead of listed tags URL. Here is the problematic part of the code. What is the correct use of `get_the_terms()`? ``` $custom_terms = g...
Keep in mind that the return value of `get_the_terms()` can be of the type of ``` array|WP_Error ``` Your snippet should check if you get the correct type returned ``` $terms = get_the_terms( 0, 'product_tag' ); if ( ! is_wp_error( $terms ) AND is_array( $terms ) AND ! empty( $terms ) ) { forea...
163,341
<p>I know there are several questions about the footer, but I did not find answer to this. If this has been asked before, my apologies.</p> <p>I am developing a widget plugin and I wanted to give users the choice, to display the copyright link in footer instead of the widget.</p> <p>I know how to display something be...
[ { "answer_id": 163420, "author": "Andreas Krischer", "author_id": 60649, "author_profile": "https://wordpress.stackexchange.com/users/60649", "pm_score": -1, "selected": false, "text": "<p>Did you changed the Wordpress URL in Settings->General?</p>\n\n<pre><code>http://example.com/wp =&g...
2014/10/03
[ "https://wordpress.stackexchange.com/questions/163341", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/47810/" ]
I know there are several questions about the footer, but I did not find answer to this. If this has been asked before, my apologies. I am developing a widget plugin and I wanted to give users the choice, to display the copyright link in footer instead of the widget. I know how to display something below the footer by...
The problem is not in WordPress, it is in your Varnish or Apache configuration. Static files, such as CSS, JS, Images, these are served by Apache without going through WordPress at all. WordPress will simply use whatever URL you configure it to use. It doesn't care about port or domains, as such. So, if your request...
163,342
<p>I took over a website from a previous developer that built most of the site. Because the theme was a custom one, he chose to do it using <a href="http://theme.wordpress.com/retired/toolbox/" rel="nofollow">Toolbox</a>. The site has been standing for just over a year, and was given to me so we can finish it.</p> <p>...
[ { "answer_id": 163420, "author": "Andreas Krischer", "author_id": 60649, "author_profile": "https://wordpress.stackexchange.com/users/60649", "pm_score": -1, "selected": false, "text": "<p>Did you changed the Wordpress URL in Settings->General?</p>\n\n<pre><code>http://example.com/wp =&g...
2014/10/03
[ "https://wordpress.stackexchange.com/questions/163342", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/59212/" ]
I took over a website from a previous developer that built most of the site. Because the theme was a custom one, he chose to do it using [Toolbox](http://theme.wordpress.com/retired/toolbox/). The site has been standing for just over a year, and was given to me so we can finish it. I have an issue where I can't upload...
The problem is not in WordPress, it is in your Varnish or Apache configuration. Static files, such as CSS, JS, Images, these are served by Apache without going through WordPress at all. WordPress will simply use whatever URL you configure it to use. It doesn't care about port or domains, as such. So, if your request...
163,363
<p>I have created a custom post type <code>'books'</code>, but I don't want to use <em>archive-books.php</em> to list the books. I need to use a static page to list my books because I would like to add content using the content editor.</p> <p>I would like this structure:<br> <em>www.example.com/books</em> ----> It is ...
[ { "answer_id": 163369, "author": "esdader", "author_id": 60630, "author_profile": "https://wordpress.stackexchange.com/users/60630", "pm_score": 3, "selected": true, "text": "<p>Set <code>has_archive</code> to <code>false</code>. In order to keep the URL structure you want (<em>/books/bo...
2014/10/03
[ "https://wordpress.stackexchange.com/questions/163363", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/16871/" ]
I have created a custom post type `'books'`, but I don't want to use *archive-books.php* to list the books. I need to use a static page to list my books because I would like to add content using the content editor. I would like this structure: *www.example.com/books* ----> It is a static page *www.example.com/bo...
Set `has_archive` to `false`. In order to keep the URL structure you want (*/books/book-name*), you'll need to add a rewrite rule: ``` 'rewrite' => array('slug' => 'books'), ```
163,365
<p>I am using a Plugin called PixGridder for backend setup, but i dont want the front-end css to apply.. I found that in the plugins functions.php has these lines: </p> <pre><code>public function front_styles() { $theme_style = get_stylesheet_directory().'/gridder.css'; if (file_exists($theme_style)...
[ { "answer_id": 163370, "author": "Otto", "author_id": 2232, "author_profile": "https://wordpress.stackexchange.com/users/2232", "pm_score": 2, "selected": true, "text": "<p>Same way you would remove it from anywhere else, be it a plugin or theme or whatever.</p>\n\n<pre><code>add_action(...
2014/10/03
[ "https://wordpress.stackexchange.com/questions/163365", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/45986/" ]
I am using a Plugin called PixGridder for backend setup, but i dont want the front-end css to apply.. I found that in the plugins functions.php has these lines: ``` public function front_styles() { $theme_style = get_stylesheet_directory().'/gridder.css'; if (file_exists($theme_style)) { w...
Same way you would remove it from anywhere else, be it a plugin or theme or whatever. ``` add_action('plugins_loaded','remove_whatever'); function remove_whatever() { if (class_exists('PixGridder')) { remove_action( 'wp_enqueue_scripts', array( PixGridder::get_instance(), 'front_styles' ) ); } } ``` ...
163,372
<p>WooCommerce's product categories are a custom taxonomy called <code>product_cat</code>. In a function I'm writing, I'm using <code>get_categories</code> with the <code>taxonomy</code> parameter set to <code>product_cat</code>. Everything works fine and I can get the term id, the name, and even the slug. What I can't...
[ { "answer_id": 163373, "author": "RachieVee", "author_id": 42783, "author_profile": "https://wordpress.stackexchange.com/users/42783", "pm_score": 5, "selected": true, "text": "<p>Another update (Sept. 2015):</p>\n\n<p>I <em>can</em> use <code>get_term_link</code> after all. The problem ...
2014/10/03
[ "https://wordpress.stackexchange.com/questions/163372", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/42783/" ]
WooCommerce's product categories are a custom taxonomy called `product_cat`. In a function I'm writing, I'm using `get_categories` with the `taxonomy` parameter set to `product_cat`. Everything works fine and I can get the term id, the name, and even the slug. What I can't figure out is how to get the link to display. ...
Another update (Sept. 2015): I *can* use `get_term_link` after all. The problem was that the string needed to be converted to an integer. Used a [Stack Overflow tip](https://stackoverflow.com/questions/7008214/php-string-to-int) for the fastest way to convert it using the (int)$value in PHP. So it would look like thi...
163,407
<p>I'm trying to get the currently login user's id in WordPress. I've used the following code: </p> <pre><code>function users_list() { global $current_user; $current_user = wp_get_current_user(); echo 'User ID: ' . $current_user-&gt;ID ; print_r($current_user); } </code></pre> <p>The above code returns ...
[ { "answer_id": 163427, "author": "Justin Bell", "author_id": 60176, "author_profile": "https://wordpress.stackexchange.com/users/60176", "pm_score": 4, "selected": true, "text": "<p>Going by <a href=\"http://codex.wordpress.org/Function_Reference/wp_get_current_user\" rel=\"noreferrer\">...
2014/10/04
[ "https://wordpress.stackexchange.com/questions/163407", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/58570/" ]
I'm trying to get the currently login user's id in WordPress. I've used the following code: ``` function users_list() { global $current_user; $current_user = wp_get_current_user(); echo 'User ID: ' . $current_user->ID ; print_r($current_user); } ``` The above code returns the empty result like: ``` W...
Going by [wp\_get\_current\_user()](http://codex.wordpress.org/Function_Reference/wp_get_current_user) information in the Codex, the function utilizes the global `$current_user` object and if necessary initializes it before use. As others have stated, `get_current_user_id()` uses this function on the backend. Consider...
163,419
<p>In the blog, i try to avoid to show two posts from the same category in succession. So if the latest two posts are from category 1, i want to skip the second one, take post 3 first (if it's not from category 21 either), and then, mixin the the skiped post before showing number 4.</p> <p>So what i have is</p> <pre>...
[ { "answer_id": 163439, "author": "jetlej", "author_id": 9862, "author_profile": "https://wordpress.stackexchange.com/users/9862", "pm_score": 1, "selected": false, "text": "<p>This stores a variable to check if the most recently displayed post was in category 1. If the next post is also ...
2014/10/04
[ "https://wordpress.stackexchange.com/questions/163419", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/16171/" ]
In the blog, i try to avoid to show two posts from the same category in succession. So if the latest two posts are from category 1, i want to skip the second one, take post 3 first (if it's not from category 21 either), and then, mixin the the skiped post before showing number 4. So what i have is ``` while (have_pos...
What about an approach like this: ``` $first_category_args = array( // category id 'cat' => 123, // get all from cat 'posts_per_page' => -1, // don't prepend sticky 'ignore_sticky_posts' => 1, // only return ids 'fields' => 'ids' ); // array of ids $fi...
163,440
<p>My client uses Karma theme with many settings in theme options. I need to keep my CSS and PHP additions in a child theme so that theme updates don't wipe it out. However when I select my child theme in Appearance > Themes, the main theme settings are all gone.</p> <p>Is there any way to preserve the main theme sett...
[ { "answer_id": 182771, "author": "andrejm", "author_id": 69892, "author_profile": "https://wordpress.stackexchange.com/users/69892", "pm_score": 3, "selected": false, "text": "<p>Wordpress theme modifications are saved in <code>wp_options</code> database table in <code>theme_mods_{themen...
2014/10/04
[ "https://wordpress.stackexchange.com/questions/163440", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/11634/" ]
My client uses Karma theme with many settings in theme options. I need to keep my CSS and PHP additions in a child theme so that theme updates don't wipe it out. However when I select my child theme in Appearance > Themes, the main theme settings are all gone. Is there any way to preserve the main theme settings?
Because of the way these theme settings are stored as an array in the database, it can be difficult to copy them over with just copy and paste in phpmyadmin or some similar tactic. The [WP CLI option command](https://developer.wordpress.org/cli/commands/option/) is your friend here. If you don't use WP CLI already, ch...
163,456
<p><strong>Background:</strong> I host a WordPress site with a hosting company that places a combined Varnish server + SSL terminator system upstream of my web server. The WordPress site runs on Apache and is accessible over both HTTP and HTTPS via the Varnish+SSL terminator.</p> <p>The setup looks like this: <img src...
[ { "answer_id": 163460, "author": "Mark Kaplun", "author_id": 23970, "author_profile": "https://wordpress.stackexchange.com/users/23970", "pm_score": 0, "selected": false, "text": "<p>There should not be a problem unless you have some misconfiguration or misbehaving theme or plugin. Wordp...
2014/10/05
[ "https://wordpress.stackexchange.com/questions/163456", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60661/" ]
**Background:** I host a WordPress site with a hosting company that places a combined Varnish server + SSL terminator system upstream of my web server. The WordPress site runs on Apache and is accessible over both HTTP and HTTPS via the Varnish+SSL terminator. The setup looks like this: ![Imgur](https://i.imgur.com/a8...
I know this is a rather old question but I'll leave my findings in case someone else needs to make this work. Your approach helped me implement a similar setup. In order for Varnish to keep a separate cache for http and https versions of the same page you simply need to add the X-Forwarded-Proto header in the hash\_d...
163,473
<p>I have currently the problem that I don't understand where the locale that is set in the header of the rendered blog comes from. The header for each post (and all other pages) looks like:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html lang="en-US"&gt; &lt;head&gt; &lt;meta charset="UTF-8" /&gt; ... </code></pre> <p...
[ { "answer_id": 163476, "author": "Giovanni Putignano", "author_id": 60293, "author_profile": "https://wordpress.stackexchange.com/users/60293", "pm_score": 2, "selected": true, "text": "<p>Locale comes from WPLANG constant defined in wp-config.php. In the last version of Wordpress (4.0, ...
2014/10/05
[ "https://wordpress.stackexchange.com/questions/163473", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/42578/" ]
I have currently the problem that I don't understand where the locale that is set in the header of the rendered blog comes from. The header for each post (and all other pages) looks like: ``` <!DOCTYPE html> <html lang="en-US"> <head> <meta charset="UTF-8" /> ... ``` I tried to find the way to influence the second l...
Locale comes from WPLANG constant defined in wp-config.php. In the last version of Wordpress (4.0, maybe 3.9) something is changing. You can install more languages setting WPLANG to different locale. Then you can select the language in the backend from Settings > General > Site language and set locale in the header. It...
163,488
<p>I'm able to add a custom field for new posts (in the admin pages), using the action hook <code>wp_insert_post</code>. But I would like to add the custom field for old posts, when I am editing the post (in the admin pages), there is any action hook to do that ?</p> <p>Sample code that I'm using:</p> <pre><code> /**...
[ { "answer_id": 163493, "author": "eballo", "author_id": 60675, "author_profile": "https://wordpress.stackexchange.com/users/60675", "pm_score": 3, "selected": true, "text": "<p>As Andreas Krischer suggested, I fixed using an script to update all the old values and then only using the <co...
2014/10/05
[ "https://wordpress.stackexchange.com/questions/163488", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60675/" ]
I'm able to add a custom field for new posts (in the admin pages), using the action hook `wp_insert_post`. But I would like to add the custom field for old posts, when I am editing the post (in the admin pages), there is any action hook to do that ? Sample code that I'm using: ``` /** * Default custom field for Mun...
As Andreas Krischer suggested, I fixed using an script to update all the old values and then only using the `wp_insert_post` to create the custom field for the new posts. The script that I used: ``` INSERT INTO wp_postmeta( post_id, meta_key, meta_value ) SELECT wp_posts.ID, 'municipi', '' FROM wp_posts WHERE wp_p...
163,524
<p>When I open the login screen on Chrome, the browser automatically fills the form with my username and password. However, when I hit the submit button, I get the following message:</p> <blockquote> <p>ERROR: The password field is empty.</p> </blockquote> <p>Adding a space to the autofilled password and removing i...
[ { "answer_id": 163525, "author": "Robbert", "author_id": 43641, "author_profile": "https://wordpress.stackexchange.com/users/43641", "pm_score": 5, "selected": true, "text": "<p>The JavaScript function <code>wp_attempt_focus</code> is causing this issue. The function fires shortly after ...
2014/10/05
[ "https://wordpress.stackexchange.com/questions/163524", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/43641/" ]
When I open the login screen on Chrome, the browser automatically fills the form with my username and password. However, when I hit the submit button, I get the following message: > > ERROR: The password field is empty. > > > Adding a space to the autofilled password and removing it again does allow me to log in....
The JavaScript function `wp_attempt_focus` is causing this issue. The function fires shortly after page load, clears the form and focuses on it, forcing users to manually enter their login information. Chrome is filling in the username and password automatically, just milliseconds before the JS function clears the fie...
163,530
<p>Hi can anyone help me to save the post title selected in this select box? I would like to let people select posts out of a dropdown select box and save the value to their profile. </p> <p>Help is very appreciated! </p> <pre><code>add_action( 'show_user_profile', 'product_selection_field', 5 ); add_action( 'edit_us...
[ { "answer_id": 163534, "author": "Giovanni Putignano", "author_id": 60293, "author_profile": "https://wordpress.stackexchange.com/users/60293", "pm_score": 0, "selected": false, "text": "<p>The code below works. I added <code>personal_options_update</code> action hook to save user profil...
2014/10/05
[ "https://wordpress.stackexchange.com/questions/163530", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60692/" ]
Hi can anyone help me to save the post title selected in this select box? I would like to let people select posts out of a dropdown select box and save the value to their profile. Help is very appreciated! ``` add_action( 'show_user_profile', 'product_selection_field', 5 ); add_action( 'edit_user_profile', 'product...
Ahh it turns out it wasn't able to stay selected because I was using the "strtolower" function to remove capital letters. Which in turn caused there to be a mismatch between the selected value and the saved value in the database. ``` add_action( 'show_user_profile', 'product_selection_field', 3 ); add_action( 'edit_u...
163,531
<p>I have a WP 4.0 site that has been installed at:</p> <pre><code>mydomain.com/site </code></pre> <p>It's been there for many years, so there are lots of links from around the web pointing to it.</p> <p>As part of an overhaul I am doing, I would like the wordpress site to be accessible at the root URI: mydomain.co...
[ { "answer_id": 163536, "author": "omega33", "author_id": 11064, "author_profile": "https://wordpress.stackexchange.com/users/11064", "pm_score": 3, "selected": true, "text": "<p>The only way I managed to get this to work was with the following in the <code>.htaccess</code> of the <em>/si...
2014/10/05
[ "https://wordpress.stackexchange.com/questions/163531", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/11064/" ]
I have a WP 4.0 site that has been installed at: ``` mydomain.com/site ``` It's been there for many years, so there are lots of links from around the web pointing to it. As part of an overhaul I am doing, I would like the wordpress site to be accessible at the root URI: mydomain.com (and www.mydomain.com), without ...
The only way I managed to get this to work was with the following in the `.htaccess` of the */site/* directory: ``` RewriteBase \ RedirectMatch 301 ^/site/$ /$1 RedirectMatch 301 ^/site/(?!wp-admin/|wp-content/|wp-includes/)(.*)$ /$1 ``` Whilst I am aware that `RewriteRule ^site/ /$1 [R=301,NC,L]` should have worked...
163,567
<p>I am trying to query multiple category in wordpress but no luck, I don’t see anything wrong with my code.</p> <p>Herewith my code below :</p> <pre><code>query_posts('posts_per_page=1&amp;cat=5,1'); while ($wp_query-&gt;have_posts()) : $wp_query-&gt;the_post(); get_template_part('loop', 'single-home'); endw...
[ { "answer_id": 163568, "author": "Zammuuz", "author_id": 40999, "author_profile": "https://wordpress.stackexchange.com/users/40999", "pm_score": 3, "selected": true, "text": "<p>Use like this</p>\n\n<pre><code>query_posts( array( 'category__in' =&gt; array(5,1), 'posts_per_page' =&gt; 1,...
2014/10/06
[ "https://wordpress.stackexchange.com/questions/163567", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60454/" ]
I am trying to query multiple category in wordpress but no luck, I don’t see anything wrong with my code. Herewith my code below : ``` query_posts('posts_per_page=1&cat=5,1'); while ($wp_query->have_posts()) : $wp_query->the_post(); get_template_part('loop', 'single-home'); endwhile; ```
Use like this ``` query_posts( array( 'category__in' => array(5,1), 'posts_per_page' => 1, 'orderby' => 'title', 'order' => 'ASC' ) ); ``` or ``` $my_query = new WP_query(array('category__and' => array(5,1))); while ($my_query->have_posts()) : $my_query->the_post(); ```
163,572
<p>By default WordPress will list posts on each category in its hierarchy. </p> <p>Example:</p> <p>Parent</p> <p>/- child</p> <p>/-- grandchild</p> <p>When viewing the "Parent" category you will see a list of posts from child, grandchild and parent - even if the post is just ticked in "Grandchild".</p> <p>My ques...
[ { "answer_id": 163583, "author": "Laurence Tuck", "author_id": 1426, "author_profile": "https://wordpress.stackexchange.com/users/1426", "pm_score": 1, "selected": false, "text": "<p>Those of us who have developed static websites with pages will understand the problem as Pieter has outli...
2014/10/06
[ "https://wordpress.stackexchange.com/questions/163572", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/1426/" ]
By default WordPress will list posts on each category in its hierarchy. Example: Parent /- child /-- grandchild When viewing the "Parent" category you will see a list of posts from child, grandchild and parent - even if the post is just ticked in "Grandchild". My question is: How do I only show posts when viewin...
There is of course the `include_children` parameter for [`WP_Query`](http://codex.wordpress.org/Class_Reference/WP_Query) as part of the [taxonomy parameters](http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters). Which I suppose should work like this for you: ``` $args = array( 'tax_query' => a...
163,586
<p>In my <code>category.php</code> template I want to sort category posts by their post types dynamic. My block must have this structure</p> <pre><code>Restaurant (custom post type) - posts Bars (custom post type) - posts Shops (custom post type) - posts </code></pre> <p>I need to know at first, in what post typ...
[ { "answer_id": 163583, "author": "Laurence Tuck", "author_id": 1426, "author_profile": "https://wordpress.stackexchange.com/users/1426", "pm_score": 1, "selected": false, "text": "<p>Those of us who have developed static websites with pages will understand the problem as Pieter has outli...
2014/10/06
[ "https://wordpress.stackexchange.com/questions/163586", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/57668/" ]
In my `category.php` template I want to sort category posts by their post types dynamic. My block must have this structure ``` Restaurant (custom post type) - posts Bars (custom post type) - posts Shops (custom post type) - posts ``` I need to know at first, in what post types are the posts of current category ...
There is of course the `include_children` parameter for [`WP_Query`](http://codex.wordpress.org/Class_Reference/WP_Query) as part of the [taxonomy parameters](http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters). Which I suppose should work like this for you: ``` $args = array( 'tax_query' => a...
163,590
<p>I need some help related to permalinks.</p> <p>I have two custom post types "books" and "authors"(created using CPT UI plugin).</p> <p>i have created few authors where the permalink is generated as <code>http://wordpressproject.localhost/author/sagar-kumar-boina</code>,(with hyphens). This pages are giving page no...
[ { "answer_id": 163583, "author": "Laurence Tuck", "author_id": 1426, "author_profile": "https://wordpress.stackexchange.com/users/1426", "pm_score": 1, "selected": false, "text": "<p>Those of us who have developed static websites with pages will understand the problem as Pieter has outli...
2014/10/06
[ "https://wordpress.stackexchange.com/questions/163590", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60718/" ]
I need some help related to permalinks. I have two custom post types "books" and "authors"(created using CPT UI plugin). i have created few authors where the permalink is generated as `http://wordpressproject.localhost/author/sagar-kumar-boina`,(with hyphens). This pages are giving page not found error. But the book...
There is of course the `include_children` parameter for [`WP_Query`](http://codex.wordpress.org/Class_Reference/WP_Query) as part of the [taxonomy parameters](http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters). Which I suppose should work like this for you: ``` $args = array( 'tax_query' => a...
163,601
<p>I am wondering where I can create menus without using the admin panel, or if it is a waste of time. In admin you can go to</p> <pre><code>Appearance =&gt; Menus </code></pre> <p>Where you can select a number of pages to add to the menu, select if it is the primary navigation in the theme etc etc</p> <p>I assume t...
[ { "answer_id": 163602, "author": "Edd Aslin", "author_id": 51738, "author_profile": "https://wordpress.stackexchange.com/users/51738", "pm_score": 1, "selected": false, "text": "<p>You can create menus using <a href=\"http://codex.wordpress.org/Function_Reference/register_nav_menus\" rel...
2014/10/06
[ "https://wordpress.stackexchange.com/questions/163601", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/51823/" ]
I am wondering where I can create menus without using the admin panel, or if it is a waste of time. In admin you can go to ``` Appearance => Menus ``` Where you can select a number of pages to add to the menu, select if it is the primary navigation in the theme etc etc I assume these menus are simply stored in the ...
Try this link may helpful <http://codex.wordpress.org/Function_Reference/wp_create_nav_menu> ``` // Check if the menu exists $menu_exists = wp_get_nav_menu_object( $menu_name ); // If it doesn't exist, let's create it. if( !$menu_exists){ $menu_id = wp_create_nav_menu($menu_name); // Set up default menu i...
163,609
<p>I need know all the categories from post in wordpress, but my code only give me the first category and I don't know for why. For example: if one post have the category "category1" and "category2" I need know the Id's from those categories.</p> <pre><code>$queryProductos = array("category_name"=&gt;"category1,catego...
[ { "answer_id": 163612, "author": "Pieter Goosen", "author_id": 31545, "author_profile": "https://wordpress.stackexchange.com/users/31545", "pm_score": 3, "selected": true, "text": "<p>Your problem lies in this piece of code</p>\n\n<pre><code>$categoriaActual = get_the_category($post-&gt;...
2014/10/06
[ "https://wordpress.stackexchange.com/questions/163609", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60178/" ]
I need know all the categories from post in wordpress, but my code only give me the first category and I don't know for why. For example: if one post have the category "category1" and "category2" I need know the Id's from those categories. ``` $queryProductos = array("category_name"=>"category1,category2,category3","o...
Your problem lies in this piece of code ``` $categoriaActual = get_the_category($post->ID); $idCategoriaActual = $categoriaActual[0]->term_id; ``` The first line gets the categories that belongs to the post in an array, that is fine (Just one note, when inside the loop, you don't need to pass the pos...
163,638
<p>I've been struggling to get HTTPS functional on my site for over ten hours now. I've got severe headache trying to set it up myself. I want you to understand that I tried several different ways to solve and asking this amazing community only as a last resort. I would really appreciate if anyone could help me out.</p...
[ { "answer_id": 167330, "author": "the", "author_id": 44793, "author_profile": "https://wordpress.stackexchange.com/users/44793", "pm_score": 2, "selected": false, "text": "<p>This appeared in WordPress 4.0.</p>\n\n<p>It's reported in <a href=\"https://core.trac.wordpress.org/ticket/29708...
2014/10/06
[ "https://wordpress.stackexchange.com/questions/163638", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60741/" ]
I've been struggling to get HTTPS functional on my site for over ten hours now. I've got severe headache trying to set it up myself. I want you to understand that I tried several different ways to solve and asking this amazing community only as a last resort. I would really appreciate if anyone could help me out. The ...
I'v added `$_SERVER['HTTPS'] = 'on';` to my **wp-config.php** as seen on [WordPress wp-admin https redirect loop](https://wordpress.stackexchange.com/questions/170165/wordpress-wp-admin-https-redirect-loop) and it worked perfectly!
163,660
<p>I want to keep the title and description of wordpress blog like this: Title | Description (showed in a tab of navigator). And I don't want to change his name while I am surfing the site.</p> <p>I think that changing a little header.php could be solution but is bad option change a file directly. Only I know that tit...
[ { "answer_id": 163663, "author": "Rarst", "author_id": 847, "author_profile": "https://wordpress.stackexchange.com/users/847", "pm_score": 3, "selected": true, "text": "<p>In any properly coded theme the title should be completely generated with <a href=\"http://queryposts.com/function/w...
2014/10/07
[ "https://wordpress.stackexchange.com/questions/163660", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/58546/" ]
I want to keep the title and description of wordpress blog like this: Title | Description (showed in a tab of navigator). And I don't want to change his name while I am surfing the site. I think that changing a little header.php could be solution but is bad option change a file directly. Only I know that title is here...
In any properly coded theme the title should be completely generated with [`wp_title()`](http://queryposts.com/function/wp_title/) and easily filterable to specific string (in `functions.php` or otherwise): ``` add_filter( 'wp_title', function () { return get_bloginfo( 'name' ) . ' | ' . get_bloginfo( 'description...
163,666
<p>I am developing a custom theme and i like to pass some variables to selected files. I am calling the view files from functions.php. </p> <pre><code>$var1 = ; $var2 = ; etc include_once('form-views/view-profile.php');//works //get_template_part('includes/form-views/view','profile');//doesn't work </code></pre> <p>...
[ { "answer_id": 163673, "author": "Rarst", "author_id": 847, "author_profile": "https://wordpress.stackexchange.com/users/847", "pm_score": 1, "selected": false, "text": "<p>This is essentially scope visibility issue. <code>include</code> brings code into a current scope, function call cr...
2014/10/07
[ "https://wordpress.stackexchange.com/questions/163666", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/9936/" ]
I am developing a custom theme and i like to pass some variables to selected files. I am calling the view files from functions.php. ``` $var1 = ; $var2 = ; etc include_once('form-views/view-profile.php');//works //get_template_part('includes/form-views/view','profile');//doesn't work ``` Now with include it works
This is essentially scope visibility issue. `include` brings code into a current scope, function call creates new closed off scope. In `get_template_part()` only certain WordPress globals are being made available by [`load_template()`](http://queryposts.com/function/load_template/) call inside. While the basic answer ...
163,677
<p>Most of the related questions are still unanswered or have very little information. I have a custom theme for my <a href="http://www.animalswecare.com" rel="nofollow">website</a> and use WordPress SEO for titles. </p> <p>All the article pages work fine, except for the pages which are created by template, i.e. <a hr...
[ { "answer_id": 166844, "author": "user995426", "author_id": 59631, "author_profile": "https://wordpress.stackexchange.com/users/59631", "pm_score": 2, "selected": false, "text": "<p>For dog breeds, I added the following code to template pages, overwriting the WP SEO functions:</p>\n\n<pr...
2014/10/07
[ "https://wordpress.stackexchange.com/questions/163677", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/59631/" ]
Most of the related questions are still unanswered or have very little information. I have a custom theme for my [website](http://www.animalswecare.com) and use WordPress SEO for titles. All the article pages work fine, except for the pages which are created by template, i.e. [/adopt-a-dog](http://www.animalswecare.c...
For dog breeds, I added the following code to template pages, overwriting the WP SEO functions: ``` function assignPageTitle() { // To set page title global $resultarray; return $resultarray->breed_title; } if ( uri_segment( 2 ) != '0' ) { add_filter( 'wpseo_title', 'assignPageTitle' ); // WP SEO functio...
163,683
<p>I am trying to show a list of the latest 3 custom post types in the footer, and while I am getting the permalink ok for the href, the title is not displaying. Here is the code I put in the footer:</p> <pre><code>$postslist = get_posts('numberposts=3&amp;order=DESC&amp;orderby=date&amp;post_type=class'); foreach ($...
[ { "answer_id": 166844, "author": "user995426", "author_id": 59631, "author_profile": "https://wordpress.stackexchange.com/users/59631", "pm_score": 2, "selected": false, "text": "<p>For dog breeds, I added the following code to template pages, overwriting the WP SEO functions:</p>\n\n<pr...
2014/10/07
[ "https://wordpress.stackexchange.com/questions/163683", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/11000/" ]
I am trying to show a list of the latest 3 custom post types in the footer, and while I am getting the permalink ok for the href, the title is not displaying. Here is the code I put in the footer: ``` $postslist = get_posts('numberposts=3&order=DESC&orderby=date&post_type=class'); foreach ($postslist as $post) : setu...
For dog breeds, I added the following code to template pages, overwriting the WP SEO functions: ``` function assignPageTitle() { // To set page title global $resultarray; return $resultarray->breed_title; } if ( uri_segment( 2 ) != '0' ) { add_filter( 'wpseo_title', 'assignPageTitle' ); // WP SEO functio...
163,696
<p>I want to query by 1 meta key, but sort by another key that may or may not exist, and <em>then</em> by post date </p> <p>So the end result would be something like:</p> <p>Meta Key A / Date 1<br> Meta Key A / Date 2<br> Meta Key B / Date 1<br> No Meta Key / Date 1<br> No Meta Key / Date 2 </p> <p>Query args like...
[ { "answer_id": 163699, "author": "Biranit Goren", "author_id": 13359, "author_profile": "https://wordpress.stackexchange.com/users/13359", "pm_score": 1, "selected": false, "text": "<p>You have a couple of errors there, I believe.</p>\n\n<p>1) There is no such parameter as 'numberposts'....
2014/10/07
[ "https://wordpress.stackexchange.com/questions/163696", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/6477/" ]
I want to query by 1 meta key, but sort by another key that may or may not exist, and *then* by post date So the end result would be something like: Meta Key A / Date 1 Meta Key A / Date 2 Meta Key B / Date 1 No Meta Key / Date 1 No Meta Key / Date 2 Query args like the following are not returning any ...
I don't think there's a way to do it without using filters. Using `posts_clauses` you could do: ``` function wpse163696_posts_clauses( $pieces, $query ) { if ( $query->get( 'orderby' ) != 'dealer_date' ) { return $pieces; } global $wpdb; $order = $query->get( 'order' ); $pieces[ 'join' ] ....
163,713
<p>I created a directory website with dropdowns in the menu allowing the user to navigate throughout the categories and sub categories. [Website]</p> <p>I am using <code>wp_dropdown_categories()</code> to display the menus and the javascript shared <a href="http://codex.wordpress.org/Function_Reference/wp_dropdown_cat...
[ { "answer_id": 166292, "author": "Paul Zee", "author_id": 31446, "author_profile": "https://wordpress.stackexchange.com/users/31446", "pm_score": 2, "selected": false, "text": "<p>I was going to add this as a comment, but my rep points aren't high enough yet :)</p>\n\n<p>I spent about 20...
2014/10/07
[ "https://wordpress.stackexchange.com/questions/163713", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/5416/" ]
I created a directory website with dropdowns in the menu allowing the user to navigate throughout the categories and sub categories. [Website] I am using `wp_dropdown_categories()` to display the menus and the javascript shared [here](http://codex.wordpress.org/Function_Reference/wp_dropdown_categories) to allow the u...
Here is a variation of the code that you use. I'm using [`get_categories()`](http://codex.wordpress.org/Function_Reference/get_categories) here to achieve the same goal. I had to adjust my code slightly to make it acceptable for your need. There are a however other modifications you have to make for this to work. When...
163,719
<p>I want my blog posts to appear inside of a form input box instead of just text on a page. Not the title, but only the submission. Is that possible.</p> <p>My index.php:</p> <pre><code>&lt;a href="&lt;?php the_permalink() ?&gt;" rel="bookmark" title="Permanent Link to &lt;?php the_title_attribute(); ?&gt;"&gt;&lt;b...
[ { "answer_id": 163748, "author": "Benjamin Cuslidge", "author_id": 60794, "author_profile": "https://wordpress.stackexchange.com/users/60794", "pm_score": 1, "selected": false, "text": "<p>Do you mean you want the Post content to be used as a placeholder text in a forms text box?</p>\n\n...
2014/10/07
[ "https://wordpress.stackexchange.com/questions/163719", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/10850/" ]
I want my blog posts to appear inside of a form input box instead of just text on a page. Not the title, but only the submission. Is that possible. My index.php: ``` <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><b><?php the_title(); ?></b> = ...
You probably want this: ``` <form action="demo_form.php"> <textarea name="blogpost" readonly="readonly"> <?php the_content(); ?> </textarea> <input type="submit" value="Submit"> </form> ```
163,730
<p>I have several custom post types, here is the creation of two of them:</p> <p>Projects</p> <pre><code>add_action( 'init', 'register_cpt_project' ); function register_cpt_project() { $labels = array( 'name' =&gt; _x( 'Projects', 'project' ), 'singular_name' =&gt; _x( 'Project', 'project' ), 'add_new'...
[ { "answer_id": 163732, "author": "Joe", "author_id": 34273, "author_profile": "https://wordpress.stackexchange.com/users/34273", "pm_score": 2, "selected": true, "text": "<p>It turns out that in my functions.php file, I had the following function:</p>\n\n<pre><code>function limit_posts_p...
2014/10/07
[ "https://wordpress.stackexchange.com/questions/163730", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/34273/" ]
I have several custom post types, here is the creation of two of them: Projects ``` add_action( 'init', 'register_cpt_project' ); function register_cpt_project() { $labels = array( 'name' => _x( 'Projects', 'project' ), 'singular_name' => _x( 'Project', 'project' ), 'add_new' => _x( 'Add New', 'project...
It turns out that in my functions.php file, I had the following function: ``` function limit_posts_per_archive_page() { if ( is_tax('project_categories') ) $limit = 9999; else $limit = get_option('posts_per_page'); set_query_var('posts_per_archive_page', $limit); } add_filter('pre_g...
163,782
<p>I have a custom theme which is in Dutch and now i am trying to translate the theme into english. For this i am using poedit, and converted some theme strings into _e('string-is-here')</p> <p>I save both en_US.po and en_US.mo into my-theme/languages and add this to functions.php</p> <pre><code>function theme_init()...
[ { "answer_id": 163791, "author": "kaiser", "author_id": 385, "author_profile": "https://wordpress.stackexchange.com/users/385", "pm_score": 0, "selected": false, "text": "<p>The <code>load_theme_textdomain()</code> function uses <code>load_textdomain()</code> internally. And that functio...
2014/10/08
[ "https://wordpress.stackexchange.com/questions/163782", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/9936/" ]
I have a custom theme which is in Dutch and now i am trying to translate the theme into english. For this i am using poedit, and converted some theme strings into \_e('string-is-here') I save both en\_US.po and en\_US.mo into my-theme/languages and add this to functions.php ``` function theme_init(){ load_theme_t...
You are making wrong assumption here. `define('WPLANG', '');` doesn't mean "original locale of the string" or anything like that, it is taken literally as "no locale specified". And when it's nothing WP proceeds to assume default locale, which is `en_US`. This is why as soon as you add English translations of string t...
163,795
<p>Inside the loop I would like to retrieve the URL of an inserted media file of each post.</p> <p>My attempt was:</p> <pre><code>&lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt; &lt;a href="&lt;?php wp_get_attachment_url(the_ID()) ?&gt;"&gt; &lt;?php the_title(); ?&gt; &lt;/a&gt; &lt;...
[ { "answer_id": 163796, "author": "Robert hue", "author_id": 22461, "author_profile": "https://wordpress.stackexchange.com/users/22461", "pm_score": 2, "selected": true, "text": "<p>You can get attachment URL like this.</p>\n\n<pre><code>&lt;?php if ( have_posts() ) : while (have_posts())...
2014/10/08
[ "https://wordpress.stackexchange.com/questions/163795", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/49869/" ]
Inside the loop I would like to retrieve the URL of an inserted media file of each post. My attempt was: ``` <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <a href="<?php wp_get_attachment_url(the_ID()) ?>"> <?php the_title(); ?> </a> <?php endwhile; ?> ``` But I can't get it to work. I ...
You can get attachment URL like this. ``` <?php if ( have_posts() ) : while (have_posts()) : the_post(); ?> <a href="<?php $featured_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); echo $featured_image_url[0]; ?>"> <?php the_title(); ?> </a> <?php endwhile; endif; ?> ...
163,801
<p>I apologise if this is an extraordinarily broad question, but I am getting a little lost.</p> <p>I am using the below to show child pages (note: I am using Advanced Custom Fields)</p> <pre><code>&lt;?php /** * Template Name: Work * Description: Work page template */ get_header(); ?&gt; &lt;div class="header...
[ { "answer_id": 163821, "author": "rob.m", "author_id": 26593, "author_profile": "https://wordpress.stackexchange.com/users/26593", "pm_score": 0, "selected": false, "text": "<p>How about using a simple css solution hiding the <code>&lt;li&gt;</code>s you don't want to show at first or us...
2014/10/08
[ "https://wordpress.stackexchange.com/questions/163801", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60816/" ]
I apologise if this is an extraordinarily broad question, but I am getting a little lost. I am using the below to show child pages (note: I am using Advanced Custom Fields) ``` <?php /** * Template Name: Work * Description: Work page template */ get_header(); ?> <div class="header-spacer"></div> <?php wh...
[Previous Question](https://stackoverflow.com/questions/15175020/dynamically-changing-navigation-links-next-and-previous-in-wordpress-via-ajax) That answer I've linked to shows the steps you'll need to take. It probably didn't come up in your searches as you weren't using the right terms. As you're a front-end dev, t...
163,802
<p>I have a WordPress installation on AWS and I was facing an issue that authors are not able to submit content like media in one go and a time-out error occurs. After refreshing the page 5-6 times authors are able to upload content again.</p> <p>To mitigate this issue, I deactivated all the plugins and upgraded to Wo...
[ { "answer_id": 300605, "author": "Suresh KUMAR Mukhiya", "author_id": 27261, "author_profile": "https://wordpress.stackexchange.com/users/27261", "pm_score": 4, "selected": false, "text": "<p>Adding these two lines to \"wp-config.php\" worked for me. I had the same issue. </p>\n\n<pre><...
2014/10/08
[ "https://wordpress.stackexchange.com/questions/163802", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60814/" ]
I have a WordPress installation on AWS and I was facing an issue that authors are not able to submit content like media in one go and a time-out error occurs. After refreshing the page 5-6 times authors are able to upload content again. To mitigate this issue, I deactivated all the plugins and upgraded to WordPress 4....
Adding these two lines to "wp-config.php" worked for me. I had the same issue. ``` define( 'CONCATENATE_SCRIPTS', false ); define( 'SCRIPT_DEBUG', true ); ``` Also, remember to clear cache on server and browser.
163,807
<p>I am trying to loop custom post-types, filtered by a custom field <code>artist-status =&gt; invited</code> and ordered by another custom field <code>last-name</code> alphabetically. Here is what I managed to write, and it doesn’t work as I need:</p> <pre><code>$args = array( 'post_type' =&gt; 'artist', 'pos...
[ { "answer_id": 163809, "author": "Giovanni Putignano", "author_id": 60293, "author_profile": "https://wordpress.stackexchange.com/users/60293", "pm_score": 0, "selected": false, "text": "<p>From <a href=\"http://codex.wordpress.org/Class_Reference/WP_Query\" rel=\"nofollow\">Codex</a> th...
2014/10/08
[ "https://wordpress.stackexchange.com/questions/163807", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/6298/" ]
I am trying to loop custom post-types, filtered by a custom field `artist-status => invited` and ordered by another custom field `last-name` alphabetically. Here is what I managed to write, and it doesn’t work as I need: ``` $args = array( 'post_type' => 'artist', 'posts_per_page' => -1, 'meta_key' => 'art...
You are sorting it incorrectly. You will need to check for `artist-status` meta key with `meta_query` and sort by `last-name` metakey. Here is your query. ``` $args = array( 'post_type' => 'artist', 'posts_per_page' => -1, 'meta_key' => 'last-name', 'orderby' => 'meta_value', 'order' => 'ASC', ...
163,808
<p>Hi I want to display a specific category from a custom query in WordPress. My code works fine and it gets the latest 4 posts, but what I want now is to retrieve a specific category. My code is below thanks :</p> <pre><code>global $wpdb; $posts = $wpdb-&gt;get_results( 'SELECT ID, post_title AS title, post_exc...
[ { "answer_id": 163810, "author": "Robert hue", "author_id": 22461, "author_profile": "https://wordpress.stackexchange.com/users/22461", "pm_score": 1, "selected": false, "text": "<p>Why are you using <code>$wpdb</code> to query from database. Use <code>WP_Query</code> or <code>get_posts<...
2014/09/30
[ "https://wordpress.stackexchange.com/questions/163808", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/-1/" ]
Hi I want to display a specific category from a custom query in WordPress. My code works fine and it gets the latest 4 posts, but what I want now is to retrieve a specific category. My code is below thanks : ``` global $wpdb; $posts = $wpdb->get_results( 'SELECT ID, post_title AS title, post_excerpt AS excerpt ...
Why are you using `$wpdb` to query from database. Use `WP_Query` or `get_posts` instead. This is how you can query from WordPress database and get 4 latest posts from category id 24. ``` <?php $args = array( 'post_type' => 'post', 'cat' => 24, 'posts_per_page' => 4, 'ignore_sticky_...
163,844
<p>I'm trying to come up with a solution where the generated image formats cover both responsive and high-resolution aspects when uploading a new item in the WP admin. I've put together a set of formats that should meet these requirements,</p> <p>2560 x 1600 retina desktop ('largex2', custom)<br> 1280 x 800 desktop (l...
[ { "answer_id": 165241, "author": "birgire", "author_id": 26350, "author_profile": "https://wordpress.stackexchange.com/users/26350", "pm_score": 4, "selected": true, "text": "<h2>1) A workaround by extending the <code>WP_Image_Editor_GD</code> class</h2>\n\n<p>The problem is how to acces...
2014/10/08
[ "https://wordpress.stackexchange.com/questions/163844", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/3390/" ]
I'm trying to come up with a solution where the generated image formats cover both responsive and high-resolution aspects when uploading a new item in the WP admin. I've put together a set of formats that should meet these requirements, 2560 x 1600 retina desktop ('largex2', custom) 1280 x 800 desktop (large) 19...
1) A workaround by extending the `WP_Image_Editor_GD` class ----------------------------------------------------------- The problem is how to access the image sizes before we change the quality of intermediate *jpeg* images. Note that the [`image_resize()`](http://codex.wordpress.org/Function_Reference/image_resize)...
163,848
<p>I was wondering if is there a way to enable to the user to send content using a form, to select different options like categories, attach images and so on, and after submit the content save as a draft in to the post. </p>
[ { "answer_id": 165241, "author": "birgire", "author_id": 26350, "author_profile": "https://wordpress.stackexchange.com/users/26350", "pm_score": 4, "selected": true, "text": "<h2>1) A workaround by extending the <code>WP_Image_Editor_GD</code> class</h2>\n\n<p>The problem is how to acces...
2014/10/08
[ "https://wordpress.stackexchange.com/questions/163848", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60835/" ]
I was wondering if is there a way to enable to the user to send content using a form, to select different options like categories, attach images and so on, and after submit the content save as a draft in to the post.
1) A workaround by extending the `WP_Image_Editor_GD` class ----------------------------------------------------------- The problem is how to access the image sizes before we change the quality of intermediate *jpeg* images. Note that the [`image_resize()`](http://codex.wordpress.org/Function_Reference/image_resize)...
163,874
<p>I am using underscore_s barebone theme to build mine and came across this challenge that I would like to style date month and year separately with CSS and the code output puts them together.</p> <p>I dug around and found out I can put formatting inside the following line of code (not sure if this is right way, trie...
[ { "answer_id": 163875, "author": "Benjamin Cuslidge", "author_id": 60794, "author_profile": "https://wordpress.stackexchange.com/users/60794", "pm_score": 0, "selected": false, "text": "<p>Output them separate like d, then m, then year. And style them according </p>\n" }, { "answ...
2014/10/09
[ "https://wordpress.stackexchange.com/questions/163874", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60850/" ]
I am using underscore\_s barebone theme to build mine and came across this challenge that I would like to style date month and year separately with CSS and the code output puts them together. I dug around and found out I can put formatting inside the following line of code (not sure if this is right way, tried everyth...
As suggested, you can break down the date format in different parts. ``` echo '<span class="date-day">' . get_the_date( 'd' ) . '</span>'; echo '<span class="date-month">' . get_the_date( 'M' ) . '</span>'; echo '<span class="date-year">' . get_the_date( 'Y' ) . '</span>'; ``` Now each item have class associated wit...
163,893
<p>I have a custom post type for a plugin I'm creating and the label for the "add an item" type of button (at the top of the list page) needs a partner-button that says "<em>import</em>" and one that says "<em>export</em>" so that I can (after a brief confirmation dialogue) allow my client to push and pull the records ...
[ { "answer_id": 185080, "author": "user98239820", "author_id": 54604, "author_profile": "https://wordpress.stackexchange.com/users/54604", "pm_score": 2, "selected": false, "text": "<p>I found a way to get it done but I am not very happy with this procedure. Please add your answer if you ...
2014/10/09
[ "https://wordpress.stackexchange.com/questions/163893", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/52853/" ]
I have a custom post type for a plugin I'm creating and the label for the "add an item" type of button (at the top of the list page) needs a partner-button that says "*import*" and one that says "*export*" so that I can (after a brief confirmation dialogue) allow my client to push and pull the records with a JSON file ...
I found a way to get it done but I am not very happy with this procedure. Please add your answer if you find better way. Mean while, this might be of help. ``` add_action('admin_head-edit.php','addCustomImportButton')); ``` I only need this on edit page, so I am using admin\_head-edit.php action, but you can use adm...
163,896
<p>I am new to WordPress but I am good with PHP programmings, if I wanted to get value from the textbox and store it in the database in WordPress can I do?</p> <p>for ex</p> <p><strong>form1.html</strong></p> <pre><code>&lt;form name="form" method="post" action="value_get.php"&gt; &lt;input type="text" id="t1" name=...
[ { "answer_id": 163897, "author": "Ram Shengale", "author_id": 56766, "author_profile": "https://wordpress.stackexchange.com/users/56766", "pm_score": 2, "selected": false, "text": "<p>A simple solution to store the value in database would be by using WordPress' <code>add_option()</code> ...
2014/10/09
[ "https://wordpress.stackexchange.com/questions/163896", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60858/" ]
I am new to WordPress but I am good with PHP programmings, if I wanted to get value from the textbox and store it in the database in WordPress can I do? for ex **form1.html** ``` <form name="form" method="post" action="value_get.php"> <input type="text" id="t1" name="t1"> <input type="submit" value="submit"> </form>...
From PHP to WordPress ===================== If you are experienced in programming and in PHP, you know that saving data coming from a form basically involves these steps: * validation * sanitization * connection to database * store value in database even if "plain" PHP would work for all of them, WordPress has helpe...
163,901
<p>I would like to use the default category for my custom post type, but when I open the category page there's no posts there.</p> <p>The loop is very simple:</p> <pre><code>&lt;?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt; &lt;div class="col-md-3 col-sm-6 col-xs-12 margin-bottom-30"&gt; &...
[ { "answer_id": 163914, "author": "Pieter Goosen", "author_id": 31545, "author_profile": "https://wordpress.stackexchange.com/users/31545", "pm_score": 5, "selected": true, "text": "<p>Custom post types are excluded from the main query by default (except on taxonomy pages and custom post ...
2014/10/09
[ "https://wordpress.stackexchange.com/questions/163901", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/38284/" ]
I would like to use the default category for my custom post type, but when I open the category page there's no posts there. The loop is very simple: ``` <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <div class="col-md-3 col-sm-6 col-xs-12 margin-bottom-30"> <?php $large_image_url = wp_get_at...
Custom post types are excluded from the main query by default (except on taxonomy pages and custom post type archive pages), that is why you don't see posts from your custom post type on your category page. You need to include your custom post type posts in the main query manually. That is done with [`pre_get_posts`](...
163,932
<p>Apart from posts and pages there are profiles on my site. Does exist some way how could I push them to the top of the search results? Currently, results are ordered at first by keyword and then by date. Problem is, the posts (about persons; e.g. announcements) are almost always newer than profiles. It is logical: pr...
[ { "answer_id": 163934, "author": "Daniel Garcia Sanchez", "author_id": 59493, "author_profile": "https://wordpress.stackexchange.com/users/59493", "pm_score": 2, "selected": false, "text": "<p>WordPress allows you to filter the results of a search.\nBy default, it search on posts and pag...
2014/10/09
[ "https://wordpress.stackexchange.com/questions/163932", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/58228/" ]
Apart from posts and pages there are profiles on my site. Does exist some way how could I push them to the top of the search results? Currently, results are ordered at first by keyword and then by date. Problem is, the posts (about persons; e.g. announcements) are almost always newer than profiles. It is logical: profi...
Since WP 3.7 there is a filter [`"posts_search_orderby"`](https://developer.wordpress.org/reference/hooks/posts_search_orderby/) that allow to set the ordering for search. To be sure that filter works as expected set `"orderby"` to `"relevance"`. ``` add_action( 'pre_get_posts', function( $query ) { if ( $query->is...
163,941
<pre><code>add_filter( 'post_row_actions', 'remove_row_actions', 10, 1 ); function remove_row_actions( $actions ) { if( get_post_type() == 'my_cpt' ) unset( $actions['view'] ); return $actions; } </code></pre> <p>This code removes the view link from post list, but I want to remove the link from post e...
[ { "answer_id": 163934, "author": "Daniel Garcia Sanchez", "author_id": 59493, "author_profile": "https://wordpress.stackexchange.com/users/59493", "pm_score": 2, "selected": false, "text": "<p>WordPress allows you to filter the results of a search.\nBy default, it search on posts and pag...
2014/10/09
[ "https://wordpress.stackexchange.com/questions/163941", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60880/" ]
``` add_filter( 'post_row_actions', 'remove_row_actions', 10, 1 ); function remove_row_actions( $actions ) { if( get_post_type() == 'my_cpt' ) unset( $actions['view'] ); return $actions; } ``` This code removes the view link from post list, but I want to remove the link from post edit page also. Can ...
Since WP 3.7 there is a filter [`"posts_search_orderby"`](https://developer.wordpress.org/reference/hooks/posts_search_orderby/) that allow to set the ordering for search. To be sure that filter works as expected set `"orderby"` to `"relevance"`. ``` add_action( 'pre_get_posts', function( $query ) { if ( $query->is...
163,974
<p>Is there any way to display different data in an <code>author.php</code> profile template depending on the role of the profile displayed? (NOT of the person viewing it, but the author that particular profile refers to). </p> <p>If a profile is being displayed of an author with role <code>editor</code>, then some co...
[ { "answer_id": 163975, "author": "gmazzap", "author_id": 35541, "author_profile": "https://wordpress.stackexchange.com/users/35541", "pm_score": 0, "selected": false, "text": "<blockquote>\n <p>Can it be done?</p>\n</blockquote>\n\n<p>Sure.</p>\n\n<p>Inside <code>author.php</code> get t...
2014/10/09
[ "https://wordpress.stackexchange.com/questions/163974", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/51936/" ]
Is there any way to display different data in an `author.php` profile template depending on the role of the profile displayed? (NOT of the person viewing it, but the author that particular profile refers to). If a profile is being displayed of an author with role `editor`, then some content would be displayed, and if...
[`current_user_can`](http://codex.wordpress.org/Function_Reference/current_user_can) does not give the desired output when working with roles. There is a [trac ticket #22624](https://core.trac.wordpress.org/ticket/22624) explaining this all. It was closed with the following > > * Keywords close removed > * Milestone ...
163,993
<p>How can I get the same output into a variable that I can then use in another function?</p> <pre><code>//get all the post ids of current projects $qry_args = array( 'post_status' =&gt; 'publish', // optional 'post_type' =&gt; 'project', // 'posts_per_page' =&gt; -1, // ALL posts 'fie...
[ { "answer_id": 163987, "author": "Brian Krogsgard", "author_id": 9333, "author_profile": "https://wordpress.stackexchange.com/users/9333", "pm_score": 1, "selected": false, "text": "<p>You have a couple of conflicting arguments here, but what you want to do is completely possible.</p>\n\...
2014/10/09
[ "https://wordpress.stackexchange.com/questions/163993", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60140/" ]
How can I get the same output into a variable that I can then use in another function? ``` //get all the post ids of current projects $qry_args = array( 'post_status' => 'publish', // optional 'post_type' => 'project', // 'posts_per_page' => -1, // ALL posts 'fields' => 'ids', ...
You have a couple of conflicting arguments here, but what you want to do is completely possible. To keep something out of the RSS feeds, and considering it really is a different type of content from your blog posts, I'd recommend a custom post type called "Links" or something. The custom post type will have its own a...
164,012
<p>I want show: Post id 5 has 100 views and rank is 2nd, post id 6 has 90 views and rank is 4th, post id 7 has 1100 views and rank is 1st</p> <p>I try:</p> <pre><code>$query="SELECT u.*,um.post_id, FIND_IN_SET( um.post_id,(SELECT GROUP_CONCAT( um.post_id ORDER BY um.meta_value * 1 DESC) ...
[ { "answer_id": 164013, "author": "Robert hue", "author_id": 22461, "author_profile": "https://wordpress.stackexchange.com/users/22461", "pm_score": 1, "selected": false, "text": "<p>Is there any specific reason you are using $wpdb? You can do the same with <code>WP_Query</code> which is ...
2014/10/10
[ "https://wordpress.stackexchange.com/questions/164012", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/34927/" ]
I want show: Post id 5 has 100 views and rank is 2nd, post id 6 has 90 views and rank is 4th, post id 7 has 1100 views and rank is 1st I try: ``` $query="SELECT u.*,um.post_id, FIND_IN_SET( um.post_id,(SELECT GROUP_CONCAT( um.post_id ORDER BY um.meta_value * 1 DESC) ...
Is there any specific reason you are using $wpdb? You can do the same with `WP_Query` which is always recommended. So if your meta key for counting post views is `views` then you can run this `WP_Query` to return top viewed posts. You can also limit results by `posts_per_page`. ``` <?php $args = array( '...
164,016
<p>I need to output the text before the_category. </p> <p>In result, it should be something like </p> <blockquote> <p>Posted on September 20, 2014 IN MyCategory</p> </blockquote> <p>Here I use <code>the_time('F j, Y')</code> and start from here I use <code>the_category()</code>.</p> <p>Word "in" should be inside ...
[ { "answer_id": 164018, "author": "Satish Gandham", "author_id": 2193, "author_profile": "https://wordpress.stackexchange.com/users/2193", "pm_score": 2, "selected": false, "text": "<p>I don't see why you can not use plain text like tho</p>\n\n<pre><code>Posted on &lt;?php the_time('F j, ...
2014/10/10
[ "https://wordpress.stackexchange.com/questions/164016", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/57564/" ]
I need to output the text before the\_category. In result, it should be something like > > Posted on September 20, 2014 IN MyCategory > > > Here I use `the_time('F j, Y')` and start from here I use `the_category()`. Word "in" should be inside the\_category and before words "MyCategory". For example, for `the...
I don't see why you can not use plain text like tho ``` Posted on <?php the_time('F j, Y') ?> in <?php the_category(); ?> ``` If what you are asking is really important, just wrap the function like this ``` my_custom_category($before='',$after=''){ echo $before; the_category() $echo $after; } ``` If the\_category...
164,030
<p>Seasoned dev, but new to wordpress development - becoming a fan very quickly.</p> <p>I'm knocking up my first wordpress plugin (custom contact form for client, none of the plugins can do the jazz I need).</p> <p>I can't work out how to submit the form and grab the data. Heres what I've got so far:</p> <pre><code>...
[ { "answer_id": 164018, "author": "Satish Gandham", "author_id": 2193, "author_profile": "https://wordpress.stackexchange.com/users/2193", "pm_score": 2, "selected": false, "text": "<p>I don't see why you can not use plain text like tho</p>\n\n<pre><code>Posted on &lt;?php the_time('F j, ...
2014/10/10
[ "https://wordpress.stackexchange.com/questions/164030", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60924/" ]
Seasoned dev, but new to wordpress development - becoming a fan very quickly. I'm knocking up my first wordpress plugin (custom contact form for client, none of the plugins can do the jazz I need). I can't work out how to submit the form and grab the data. Heres what I've got so far: ``` function cafesignup_function...
I don't see why you can not use plain text like tho ``` Posted on <?php the_time('F j, Y') ?> in <?php the_category(); ?> ``` If what you are asking is really important, just wrap the function like this ``` my_custom_category($before='',$after=''){ echo $before; the_category() $echo $after; } ``` If the\_category...