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
79,933
<p>I have a website with the following categories:</p> <ul> <li>Videos</li> <li>Pictures</li> <li>Stories</li> </ul> <p>And I have a lot of tags like: <code>Funny</code>, <code>Awesome</code>, <code>Mind Blowing</code>, <code>Crazy</code>, etc.</p> <p>Is there a way I could filter lets say: <code>Videos</code> tagge...
[ { "answer_id": 79937, "author": "fuxia", "author_id": 73, "author_profile": "https://wordpress.stackexchange.com/users/73", "pm_score": 2, "selected": false, "text": "<p>You can add the category as parameter:</p>\n\n<pre><code>http://example.com/tag/crazy?category=videos\n</code></pre>\n...
2013/01/09
[ "https://wordpress.stackexchange.com/questions/79933", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/21245/" ]
I have a website with the following categories: * Videos * Pictures * Stories And I have a lot of tags like: `Funny`, `Awesome`, `Mind Blowing`, `Crazy`, etc. Is there a way I could filter lets say: `Videos` tagged as `Crazy`? I know you can do: ``` http://domainname.com/tag/crazy/ ``` But that would retrieve A...
Another way that @toscho's solution made me try, and worked for me, is this scheme: ``` http://example.com/videos/?tag=crazy ```
79,934
<p>I have an array of image id's and i want assign them to the specific post:</p> <pre><code>foreach ($image_ids as $image_id) var_dump(wp_insert_post(array('ID' =&gt; $image_id, 'post_parent' =&gt; $new_post_id), TRUE)); </code></pre> <p>But there occurs error:</p> <pre><code>object(WP_Error)#252 (2) { ["err...
[ { "answer_id": 79936, "author": "fuxia", "author_id": 73, "author_profile": "https://wordpress.stackexchange.com/users/73", "pm_score": 4, "selected": true, "text": "<p>Use <code>wp_update_post()</code>, not <code>insert</code>.</p>\n\n<pre><code>wp_update_post(\n array(\n 'ID'...
2013/01/09
[ "https://wordpress.stackexchange.com/questions/79934", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/22622/" ]
I have an array of image id's and i want assign them to the specific post: ``` foreach ($image_ids as $image_id) var_dump(wp_insert_post(array('ID' => $image_id, 'post_parent' => $new_post_id), TRUE)); ``` But there occurs error: ``` object(WP_Error)#252 (2) { ["errors"]=> array(1) { ["empty_content"]=...
Use `wp_update_post()`, not `insert`. ``` wp_update_post( array( 'ID' => $image_id, 'post_parent' => $new_post_id ) ); ```
79,938
<p>I've seen this convention pretty much everywhere, and, at times, it comes close to driving me nuts:</p> <pre><code>&lt;?php //The loop ?&gt; &lt;?php while ( have_posts() ) : the_post(); ?&gt; &lt;?php the_content(); ?&gt; &lt;?php endwhile; // end of the loop. ?&gt; </code></pre> <p>Where the <code>&lt;?php</...
[ { "answer_id": 79940, "author": "fuxia", "author_id": 73, "author_profile": "https://wordpress.stackexchange.com/users/73", "pm_score": 6, "selected": true, "text": "<p>This is not recommended in any WordPress style guide, and I think it is a bad coding style. Beginners are using this st...
2013/01/09
[ "https://wordpress.stackexchange.com/questions/79938", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25803/" ]
I've seen this convention pretty much everywhere, and, at times, it comes close to driving me nuts: ``` <?php //The loop ?> <?php while ( have_posts() ) : the_post(); ?> <?php the_content(); ?> <?php endwhile; // end of the loop. ?> ``` Where the `<?php` and closing `?>` are on every single line, even if there i...
This is not recommended in any WordPress style guide, and I think it is a bad coding style. Beginners are using this style, maybe because it feels more like HTML … Unfortunately, the default themes are using this style way too often, so some beginners might think it is part of a code style. One disadvantage of this s...
79,957
<p>I used remove_shortcode('gallery'); ...the gallery is gone, but the shortcode is visible in the text. How do I remove sitewide? I've searched for sql queries, but no solution fixes my specific problem. </p> <p><img src="https://i.stack.imgur.com/3GWzB.png" alt="gallery shortcode still visible"></p>
[ { "answer_id": 79959, "author": "fuxia", "author_id": 73, "author_profile": "https://wordpress.stackexchange.com/users/73", "pm_score": 3, "selected": false, "text": "<p>You can make it invisible with a simple trick:</p>\n\n<pre><code>add_shortcode( 'gallery', '__return_false' );\n</code...
2013/01/10
[ "https://wordpress.stackexchange.com/questions/79957", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25714/" ]
I used remove\_shortcode('gallery'); ...the gallery is gone, but the shortcode is visible in the text. How do I remove sitewide? I've searched for sql queries, but no solution fixes my specific problem. ![gallery shortcode still visible](https://i.stack.imgur.com/3GWzB.png)
The short code is actually entered into then page or post content so disabling the short code processing prevents the gallery short code from being replaced with the gallery images but it doesn't affect the post content. The best solution is to add a new short code handler after removing the default gallery handles. A...
79,967
<p>This seems like it should be something that's really simple to do, however it's apparently not.</p> <p>I don't want tags to be links, but I want them to display in an unordered list, with each tag inside an <code>&lt;li&gt;</code></p> <p>get_the_tags allows you to echo them without the associated link, but I have ...
[ { "answer_id": 79968, "author": "Jake Lisby", "author_id": 25283, "author_profile": "https://wordpress.stackexchange.com/users/25283", "pm_score": 4, "selected": true, "text": "<p>This would do it...</p>\n\n<pre><code> &lt;?php\n$posttags = get_the_tags();\nif ($posttags) {\n echo '&lt;...
2013/01/10
[ "https://wordpress.stackexchange.com/questions/79967", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/22450/" ]
This seems like it should be something that's really simple to do, however it's apparently not. I don't want tags to be links, but I want them to display in an unordered list, with each tag inside an `<li>` get\_the\_tags allows you to echo them without the associated link, but I have no idea how to wrap them in li's...
This would do it... ``` <?php $posttags = get_the_tags(); if ($posttags) { echo '<ul>'; foreach($posttags as $tag) { echo '<li>' .$tag->name. '</li>'; } echo '</ul>'; } ?> ```
79,978
<p>I have some code that display's the titles of my child category posts on one of my pages:</p> <pre><code>&lt;?php $parent = get_cat_ID("photos"); $cats = get_categories('child_of='.$parent); foreach ($cats as $cat) { echo "&lt;ul&gt;"; echo sprintf("&lt;li&gt;&lt;a href='%s'&gt;%s&lt;/a&...
[ { "answer_id": 79997, "author": "Mike Madern", "author_id": 24806, "author_profile": "https://wordpress.stackexchange.com/users/24806", "pm_score": 3, "selected": true, "text": "<p>You can get a random post by category by using the following code:</p>\n\n<pre><code>query_posts( array (\n...
2013/01/10
[ "https://wordpress.stackexchange.com/questions/79978", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/9820/" ]
I have some code that display's the titles of my child category posts on one of my pages: ``` <?php $parent = get_cat_ID("photos"); $cats = get_categories('child_of='.$parent); foreach ($cats as $cat) { echo "<ul>"; echo sprintf("<li><a href='%s'>%s</a></li>", get_category_link($cat->term_i...
You can get a random post by category by using the following code: ``` query_posts( array ( 'showposts' => 1, 'orderby' => 'rand', 'cat' => $cat->term_id ) ); if ( have_posts() ) : while ( have_posts() ) : the_post(); ... ``` And then use [get\_the\_post\_thumbnail()](http://codex.wordpress.org/...
79,989
<p>I have the following query:</p> <pre><code>SELECT p.* FROM orders_items oi INNER JOIN products pr ON pr.`post_id` = oi.`product_id` INNER JOIN posts p ON p.`ID` = pr.`post_id` AND p.`post_type` = 'product' GROUP BY oi.`product_id` ORDER BY COUNT(oi.id) DESC; </code></pre> <p>I want to list the ...
[ { "answer_id": 79997, "author": "Mike Madern", "author_id": 24806, "author_profile": "https://wordpress.stackexchange.com/users/24806", "pm_score": 3, "selected": true, "text": "<p>You can get a random post by category by using the following code:</p>\n\n<pre><code>query_posts( array (\n...
2013/01/10
[ "https://wordpress.stackexchange.com/questions/79989", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25827/" ]
I have the following query: ``` SELECT p.* FROM orders_items oi INNER JOIN products pr ON pr.`post_id` = oi.`product_id` INNER JOIN posts p ON p.`ID` = pr.`post_id` AND p.`post_type` = 'product' GROUP BY oi.`product_id` ORDER BY COUNT(oi.id) DESC; ``` I want to list the post based on the above qu...
You can get a random post by category by using the following code: ``` query_posts( array ( 'showposts' => 1, 'orderby' => 'rand', 'cat' => $cat->term_id ) ); if ( have_posts() ) : while ( have_posts() ) : the_post(); ... ``` And then use [get\_the\_post\_thumbnail()](http://codex.wordpress.org/...
79,994
<p>I want to show hidden password fields on registration form. I found that these fields are already present in /wp-admin/user-new.php</p> <pre><code>&lt;?php if ( apply_filters('show_password_fields', true) ) : ?&gt; &lt;tr class="form-field form-required"&gt; &lt;th scope="row"&gt;&lt;label for="pass1"&gt;&lt;?p...
[ { "answer_id": 80001, "author": "shea", "author_id": 19726, "author_profile": "https://wordpress.stackexchange.com/users/19726", "pm_score": 1, "selected": false, "text": "<p><code>show_passwords_fields</code> actually <em>is</em> a filter! You can hook into it as you did above, using an...
2013/01/10
[ "https://wordpress.stackexchange.com/questions/79994", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25831/" ]
I want to show hidden password fields on registration form. I found that these fields are already present in /wp-admin/user-new.php ``` <?php if ( apply_filters('show_password_fields', true) ) : ?> <tr class="form-field form-required"> <th scope="row"><label for="pass1"><?php _e('Password'); ?> <span class="descri...
`show_passwords_fields` actually *is* a filter! You can hook into it as you did above, using an anonymous function: ``` add_filter( 'show_password_fields', function(){return true} ); ``` You can also write a function, and use it as a callback: ``` function wpse_79994_show_password_fields() { return true; } add_...
79,996
<p>In Wordpress, when creating a page, it shows some options for Template under Attributes, such as: Default, Links, One column no sidebar, etc.</p> <p>Is there a way to add more custom templates to show up here? If so, how?</p>
[ { "answer_id": 79998, "author": "Arvind Pal", "author_id": 12858, "author_profile": "https://wordpress.stackexchange.com/users/12858", "pm_score": 1, "selected": false, "text": "<pre><code>You can create your own template for pages. Below link shows the example of creating template.\n\nU...
2013/01/10
[ "https://wordpress.stackexchange.com/questions/79996", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18225/" ]
In Wordpress, when creating a page, it shows some options for Template under Attributes, such as: Default, Links, One column no sidebar, etc. Is there a way to add more custom templates to show up here? If so, how?
All you need to do is just create a new file in your theme root directory. This file must start with following code: ``` <?php /** * Template Name: No Sidebars */ ``` Name your file, for example, `page_nosidebars.php` and then WP will add `No Sidebars` template to available templates list. There is nice article...
80,008
<p>I have seen many snippets to display random post/posts on a page. Most of them provide a function or wp_query code to be directly placed where it is required. In the end they tell to create a template random.php and page with name RANDOM. So, when one wants to access that page, they can look for a link pointing as <...
[ { "answer_id": 80011, "author": "Just Thomas Misund", "author_id": 20580, "author_profile": "https://wordpress.stackexchange.com/users/20580", "pm_score": 2, "selected": true, "text": "<p>What you are asking is how to redirect the visitor to a random post. Here you go:</p>\n\n<pre><code>...
2013/01/10
[ "https://wordpress.stackexchange.com/questions/80008", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/24411/" ]
I have seen many snippets to display random post/posts on a page. Most of them provide a function or wp\_query code to be directly placed where it is required. In the end they tell to create a template random.php and page with name RANDOM. So, when one wants to access that page, they can look for a link pointing as <ht...
What you are asking is how to redirect the visitor to a random post. Here you go: ``` <?php /* * Template Name: Random Redirect */ query_posts( array( 'showposts' => 1, 'orderby' => 'rand', ) ); if (have_posts()) : while (have_posts()) : the_post(); header( 'Location: ' . get_the_permalink...
80,014
<p>On my homepage I am using a code to call different post type labels. Example:</p> <blockquote> <p>TV Series: "Once Upon A Time"</p> </blockquote> <p>Here is the code I use to call the label:</p> <pre><code>&lt;a href="&lt;?php echo get_post_type( $post-&gt;ID ); ?&gt;"&gt; &lt;?php $post_type = get_post_typ...
[ { "answer_id": 80016, "author": "Rohit Pande", "author_id": 21274, "author_profile": "https://wordpress.stackexchange.com/users/21274", "pm_score": 3, "selected": true, "text": "<p>You can do something like this:</p>\n\n<pre><code>&lt;a href=\"&lt;?php echo get_post_type( $post-&gt;ID );...
2013/01/10
[ "https://wordpress.stackexchange.com/questions/80014", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/20145/" ]
On my homepage I am using a code to call different post type labels. Example: > > TV Series: "Once Upon A Time" > > > Here is the code I use to call the label: ``` <a href="<?php echo get_post_type( $post->ID ); ?>"> <?php $post_type = get_post_type_object( get_post_type( $post ) ); echo $post_type->labe...
You can do something like this: ``` <a href="<?php echo get_post_type( $post->ID ); ?>" class="<?php echo str_replace(' ', '-', get_post_type( $post->ID )); ?>"> <?php $post_type = get_post_type_object( get_post_type($post) ); echo $post_type->label ; ?> </a> ``` and in your **CSS** part you can do something li...
80,018
<p>I'm just trying to turn off the wp admin bar on one page, but this function removes it from every page. What am I missing?</p> <pre><code>&lt;?php if ( !is_page('image-upload') ): show_admin_bar(false); endif; ?&gt; </code></pre>
[ { "answer_id": 80020, "author": "Pontus Abrahamsson", "author_id": 16722, "author_profile": "https://wordpress.stackexchange.com/users/16722", "pm_score": 2, "selected": true, "text": "<p>You need to remove the (!) infront of the conditional, you can read about <a href=\"http://www.w3sch...
2013/01/10
[ "https://wordpress.stackexchange.com/questions/80018", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25137/" ]
I'm just trying to turn off the wp admin bar on one page, but this function removes it from every page. What am I missing? ``` <?php if ( !is_page('image-upload') ): show_admin_bar(false); endif; ?> ```
You need to remove the (!) infront of the conditional, you can read about [PHP-operators here](http://www.w3schools.com/php/php_operators.asp). Now you simply say that if not on page "image-upload" remove the admin\_bar.. Here is the working code: ``` <?php function wpse_80018_hide_admin_bar() { // If is on page ...
80,026
<p>I'm constantly reading stuff on the wordpress forum where people are making all mannar of customizations by modifying php or css files using the file editor. But aren't all those files generated? Don't these files get reverted when a change is made to the website through the wp-admin console or when wordpress update...
[ { "answer_id": 80033, "author": "fuxia", "author_id": 73, "author_profile": "https://wordpress.stackexchange.com/users/73", "pm_score": 3, "selected": true, "text": "<p>Updates run for themes and plugins only if there is a registered update server. If you have a custom (child) theme, or ...
2013/01/10
[ "https://wordpress.stackexchange.com/questions/80026", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25836/" ]
I'm constantly reading stuff on the wordpress forum where people are making all mannar of customizations by modifying php or css files using the file editor. But aren't all those files generated? Don't these files get reverted when a change is made to the website through the wp-admin console or when wordpress updates?
Updates run for themes and plugins only if there is a registered update server. If you have a custom (child) theme, or a plugin not hosted on wordpress.org and without a custom update mechanism there will be no updates. In all other cases: Yes, you are right, the changes could be overwritten. But this is not the only...
80,027
<p>I am using wp 3.5 i have a custom post <code>(sp_product)</code> and also i have custom taxonomy. I want to remove that custom taxonomy filter column but i don't want to make <code>'show_admin_column' =&gt; false</code>.</p> <p>I wanna unset from <code>$columns['']</code> .</p> <p>How should i do that ? i also wan...
[ { "answer_id": 80038, "author": "Selva Balaji", "author_id": 25011, "author_profile": "https://wordpress.stackexchange.com/users/25011", "pm_score": 0, "selected": false, "text": "<pre>\nadd_action( 'init', 'unregister_taxonomy');\nfunction unregister_taxonomy(){\n global $wp_taxonomi...
2013/01/10
[ "https://wordpress.stackexchange.com/questions/80027", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25597/" ]
I am using wp 3.5 i have a custom post `(sp_product)` and also i have custom taxonomy. I want to remove that custom taxonomy filter column but i don't want to make `'show_admin_column' => false`. I wanna unset from `$columns['']` . How should i do that ? i also want to add some css/js when it will show in column and ...
``` function wpse_80027_manage_columns($columns) { // remove taxonomy column unset($columns['taxonomy-YOUR_TAXONOMY_NAME']); // prepend taxonomy name with 'taxonomy-' // add your custom column $columns['CUSTOM_COLUMN_NAME'] = __('Column Name'); return $columns; } add_filter('manage_edit-sp_product_c...
80,044
<p>I am currently in the process of building a responsive real estate WordPress theme and I'm figuring out how to properly add support for HiDPI screens. I decided to use a JavaScript solution <a href="https://github.com/scottjehl/picturefill" rel="nofollow">Picturefill</a>, which mimics the functionality of <a href="h...
[ { "answer_id": 80038, "author": "Selva Balaji", "author_id": 25011, "author_profile": "https://wordpress.stackexchange.com/users/25011", "pm_score": 0, "selected": false, "text": "<pre>\nadd_action( 'init', 'unregister_taxonomy');\nfunction unregister_taxonomy(){\n global $wp_taxonomi...
2013/01/10
[ "https://wordpress.stackexchange.com/questions/80044", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/15865/" ]
I am currently in the process of building a responsive real estate WordPress theme and I'm figuring out how to properly add support for HiDPI screens. I decided to use a JavaScript solution [Picturefill](https://github.com/scottjehl/picturefill), which mimics the functionality of [proposed picture HTML element](http://...
``` function wpse_80027_manage_columns($columns) { // remove taxonomy column unset($columns['taxonomy-YOUR_TAXONOMY_NAME']); // prepend taxonomy name with 'taxonomy-' // add your custom column $columns['CUSTOM_COLUMN_NAME'] = __('Column Name'); return $columns; } add_filter('manage_edit-sp_product_c...
80,045
<p>I have a question. I need to have, in my archive.php file, a exclusion of a specific category. given what I have now, how would I make that happen?</p> <p>Here is the code:</p> <pre><code> &lt;?php query_posts(array( 'post_type' =&gt; 'post', 'showposts' =&gt; 5 ) ); ...
[ { "answer_id": 80038, "author": "Selva Balaji", "author_id": 25011, "author_profile": "https://wordpress.stackexchange.com/users/25011", "pm_score": 0, "selected": false, "text": "<pre>\nadd_action( 'init', 'unregister_taxonomy');\nfunction unregister_taxonomy(){\n global $wp_taxonomi...
2013/01/10
[ "https://wordpress.stackexchange.com/questions/80045", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/15302/" ]
I have a question. I need to have, in my archive.php file, a exclusion of a specific category. given what I have now, how would I make that happen? Here is the code: ``` <?php query_posts(array( 'post_type' => 'post', 'showposts' => 5 ) ); ?> <?php while (have_post...
``` function wpse_80027_manage_columns($columns) { // remove taxonomy column unset($columns['taxonomy-YOUR_TAXONOMY_NAME']); // prepend taxonomy name with 'taxonomy-' // add your custom column $columns['CUSTOM_COLUMN_NAME'] = __('Column Name'); return $columns; } add_filter('manage_edit-sp_product_c...
80,050
<p>I've seen a few questions similar to this but I can't find a solution to the issue I have.</p> <pre><code>&lt;?php add_action('wp_ajax_nopriv_LogHit_callback', 'LogHit_callback'); add_action('wp_ajax_LogHit_callback', 'LogHit_callback'); function HitCount() { ?&gt; &lt;script type="text/javascript" &gt; jQuer...
[ { "answer_id": 80052, "author": "s_ha_dum", "author_id": 21376, "author_profile": "https://wordpress.stackexchange.com/users/21376", "pm_score": 3, "selected": true, "text": "<p>You are making a new request to the server and you appear to be loading a page that is not loading WordPress c...
2013/01/10
[ "https://wordpress.stackexchange.com/questions/80050", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25843/" ]
I've seen a few questions similar to this but I can't find a solution to the issue I have. ``` <?php add_action('wp_ajax_nopriv_LogHit_callback', 'LogHit_callback'); add_action('wp_ajax_LogHit_callback', 'LogHit_callback'); function HitCount() { ?> <script type="text/javascript" > jQuery(document).ready(function...
You are making a new request to the server and you appear to be loading a page that is not loading WordPress core functions. I'd need to see your `HitCount.php` to confirm this but I can't think of another explanation. Loading WordPRess files piecemeal is tricky and prone to breakage as core code changes. You can pro...
80,051
<p>I have a wordpress site, I downloaded it from live and configured it on local using xampp. When i click on any post, it redirects me to <code>localhost/xampp</code> instead of post page my .htaccess is like</p> <pre><code>&lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] R...
[ { "answer_id": 80055, "author": "Ruhul Amin", "author_id": 25776, "author_profile": "https://wordpress.stackexchange.com/users/25776", "pm_score": 0, "selected": false, "text": "<p>I think, you took database from localhost. If so then go to phpmyadmin and click on wp_options table. at f...
2013/01/10
[ "https://wordpress.stackexchange.com/questions/80051", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25844/" ]
I have a wordpress site, I downloaded it from live and configured it on local using xampp. When i click on any post, it redirects me to `localhost/xampp` instead of post page my .htaccess is like ``` <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} ...
Your rewrite rule is wrong. The existing rule is for when the site is at root-- `http://localhost`. You site is at `http://localhost/highimpact`. The final rewrite rule should, I believe, `RewriteRule . /highimpact/index.php [L]`. If you go to wp-admin->Permalinks, and save the settings WordPress will rewrite the rul...
80,063
<p>I have a custom taxonomy filled with terms such as 'volume 1', 'volume 2', 'issue 1', 'issue 2', 'issue 10' and get_terms orderby name returns list as: issue 1, issue 10, issue 2 though I need it to be issue 1, issue 2, issue 10</p> <p>I tried searching wp.stackexchange and using my google-fu to no avail. Any help ...
[ { "answer_id": 80067, "author": "s_ha_dum", "author_id": 21376, "author_profile": "https://wordpress.stackexchange.com/users/21376", "pm_score": 1, "selected": false, "text": "<p>There are many similar posts on the forum, if you look around. </p>\n\n<p>You <strong>do not have numbers</st...
2013/01/10
[ "https://wordpress.stackexchange.com/questions/80063", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/24231/" ]
I have a custom taxonomy filled with terms such as 'volume 1', 'volume 2', 'issue 1', 'issue 2', 'issue 10' and get\_terms orderby name returns list as: issue 1, issue 10, issue 2 though I need it to be issue 1, issue 2, issue 10 I tried searching wp.stackexchange and using my google-fu to no avail. Any help would be ...
I know this post is very old but still answering for others who reach here. Following is a very simple filter to sort the terms as numbers. You only need to set the variable `$taxonomy_to_sort` with `taxonomy slug` and place it in `functions.php` of your theme. ``` add_filter( 'get_terms_orderby', 'terms_order_as_num...
80,068
<p>Is it possible to sort product categories? </p> <p>I have a category with a lot of subcategories. On the category page all the subcategories is listed. Right now I can only change the order by drag and drop in the admin panel. But that is very time consuming with a lot of categories. Any way to change the order wit...
[ { "answer_id": 80096, "author": "webaware", "author_id": 24260, "author_profile": "https://wordpress.stackexchange.com/users/24260", "pm_score": 1, "selected": false, "text": "<p>You can sort product categories by drag-and-drop. Notice that your mouse cursor turns into a hand when over a...
2013/01/10
[ "https://wordpress.stackexchange.com/questions/80068", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25851/" ]
Is it possible to sort product categories? I have a category with a lot of subcategories. On the category page all the subcategories is listed. Right now I can only change the order by drag and drop in the admin panel. But that is very time consuming with a lot of categories. Any way to change the order without using...
Woocommerce stores 'order' metakeys in the table `wp_woocommerce_termmeta`. The mechanism it uses is the same as `menu_order` for posts. Something like this should work: ``` $terms = get_terms('product_cat'); //sort $terms somehow $i = -1; foreach ($terms as $term) { $i++; update_woocommerce_term_meta( $term->...
80,088
<p>How can i get the count for published post from my custom post type , from my taxonomy.</p> <p>I have Custom Post Type : trailers, Taxonomy : trailere-noi</p> <pre><code>&lt;?php $items = get_posts( array( 'post_type' =&gt; 'trailers', 'numberposts' =&gt; -1, 'taxonomy' =&gt; 'trailere-noi', ...
[ { "answer_id": 80091, "author": "Rommel Castro A", "author_id": 24130, "author_profile": "https://wordpress.stackexchange.com/users/24130", "pm_score": 2, "selected": false, "text": "<p>try something like this:</p>\n\n<pre><code>$items = get_posts( array(\n 'post_type' =&gt; 'traile...
2013/01/10
[ "https://wordpress.stackexchange.com/questions/80088", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/17885/" ]
How can i get the count for published post from my custom post type , from my taxonomy. I have Custom Post Type : trailers, Taxonomy : trailere-noi ``` <?php $items = get_posts( array( 'post_type' => 'trailers', 'numberposts' => -1, 'taxonomy' => 'trailere-noi', )); $count = count( $posts ); ...
try something like this: ``` $items = get_posts( array( 'post_type' => 'trailers', 'numberposts' => -1, 'taxonomy' => 'trailere-noi', )); echo $posts->post_count; ```
80,112
<p>I have built a plugin that displays a table using the WP_List_Table class. The table displays entries on which it's possible to apply a filter and some bulk actions.</p> <p>The problem is that when I click on the "filter" button or "apply bulk action" button multiple times, the _wp_http_referer paramater is added t...
[ { "answer_id": 80114, "author": "diggy", "author_id": 25765, "author_profile": "https://wordpress.stackexchange.com/users/25765", "pm_score": 4, "selected": true, "text": "<p>As the last commenter on that Q suggested, you should probably check for actions, remove the query args and redir...
2013/01/11
[ "https://wordpress.stackexchange.com/questions/80112", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/23605/" ]
I have built a plugin that displays a table using the WP\_List\_Table class. The table displays entries on which it's possible to apply a filter and some bulk actions. The problem is that when I click on the "filter" button or "apply bulk action" button multiple times, the \_wp\_http\_referer paramater is added to the...
As the last commenter on that Q suggested, you should probably check for actions, remove the query args and redirect. Something like: ``` $doaction = $wp_list_table->current_action(); if ( $doaction && isset( $_REQUEST['SOMEVAR'] ) ) { // do stuff } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) { wp_redirect...
80,121
<p>The way WordPress handles taxonomies and terms isn't fool proof enough for the users of a project I am currently working on. </p> <p>Here's the example I need:</p> <p>I have a "Conference" taxonomy, a "Divisions" taxonomy, and a "Teams" taxonomy.</p> <p>I need the Divisions to be a child of the Conference and the...
[ { "answer_id": 80114, "author": "diggy", "author_id": 25765, "author_profile": "https://wordpress.stackexchange.com/users/25765", "pm_score": 4, "selected": true, "text": "<p>As the last commenter on that Q suggested, you should probably check for actions, remove the query args and redir...
2013/01/11
[ "https://wordpress.stackexchange.com/questions/80121", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25870/" ]
The way WordPress handles taxonomies and terms isn't fool proof enough for the users of a project I am currently working on. Here's the example I need: I have a "Conference" taxonomy, a "Divisions" taxonomy, and a "Teams" taxonomy. I need the Divisions to be a child of the Conference and the Teams to be the child o...
As the last commenter on that Q suggested, you should probably check for actions, remove the query args and redirect. Something like: ``` $doaction = $wp_list_table->current_action(); if ( $doaction && isset( $_REQUEST['SOMEVAR'] ) ) { // do stuff } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) { wp_redirect...
80,138
<p>I have installed Ambrosite Next/Previous Post Link Plus and I'm not sure how to configure it to achieve what I'm looking for.</p> <p>I have a post category like below:</p> <p><strong>Parent category -> Sub category -> Post</strong></p> <p>If I use the traditional WP next_post links I can use TRUE or FALSE to cycl...
[ { "answer_id": 80114, "author": "diggy", "author_id": 25765, "author_profile": "https://wordpress.stackexchange.com/users/25765", "pm_score": 4, "selected": true, "text": "<p>As the last commenter on that Q suggested, you should probably check for actions, remove the query args and redir...
2013/01/11
[ "https://wordpress.stackexchange.com/questions/80138", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/23226/" ]
I have installed Ambrosite Next/Previous Post Link Plus and I'm not sure how to configure it to achieve what I'm looking for. I have a post category like below: **Parent category -> Sub category -> Post** If I use the traditional WP next\_post links I can use TRUE or FALSE to cycle through either all posts on the si...
As the last commenter on that Q suggested, you should probably check for actions, remove the query args and redirect. Something like: ``` $doaction = $wp_list_table->current_action(); if ( $doaction && isset( $_REQUEST['SOMEVAR'] ) ) { // do stuff } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) { wp_redirect...
80,145
<p>is there any way to change the default output when inserting a video into tinyMCE with Wordpress' default media manager. Currently it inserts it as a link, would it be possible to input it into the editor as an iFrame with all attributes intact.</p> <p>Thanks in advance!</p>
[ { "answer_id": 80114, "author": "diggy", "author_id": 25765, "author_profile": "https://wordpress.stackexchange.com/users/25765", "pm_score": 4, "selected": true, "text": "<p>As the last commenter on that Q suggested, you should probably check for actions, remove the query args and redir...
2013/01/11
[ "https://wordpress.stackexchange.com/questions/80145", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/22934/" ]
is there any way to change the default output when inserting a video into tinyMCE with Wordpress' default media manager. Currently it inserts it as a link, would it be possible to input it into the editor as an iFrame with all attributes intact. Thanks in advance!
As the last commenter on that Q suggested, you should probably check for actions, remove the query args and redirect. Something like: ``` $doaction = $wp_list_table->current_action(); if ( $doaction && isset( $_REQUEST['SOMEVAR'] ) ) { // do stuff } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) { wp_redirect...
80,153
<p>I'm just getting used to the WP Query and was hoping I could get some assistance on this.</p> <p>I've created a custom taxonomy (theme) and now want to display the latest post with one of these taxonomies on my front page as a top featured post.</p> <p>Now I can't really seem to work out how to get it to filter th...
[ { "answer_id": 80154, "author": "aguidis", "author_id": 23524, "author_profile": "https://wordpress.stackexchange.com/users/23524", "pm_score": 1, "selected": true, "text": "<p>You have to use your object like this :</p>\n\n<pre><code>while ( $query-&gt;have_posts() ) : $query-&gt;the_po...
2013/01/11
[ "https://wordpress.stackexchange.com/questions/80153", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25846/" ]
I'm just getting used to the WP Query and was hoping I could get some assistance on this. I've created a custom taxonomy (theme) and now want to display the latest post with one of these taxonomies on my front page as a top featured post. Now I can't really seem to work out how to get it to filter the query properly,...
You have to use your object like this : ``` while ( $query->have_posts() ) : $query->the_post(); ```
80,158
<p>The following code does not produce a UL with ID of "nav". It just produces </p> <pre><code>&lt;div class="menu"&gt;&lt;ul&gt; </code></pre> <p>This is the code:</p> <pre><code>wp_nav_menu( array( 'theme_location' =&gt; 'menu-1', 'container_id' =&gt; 'nav'; </code></pre> <p>According the <a href="http://cod...
[ { "answer_id": 80159, "author": "Joseph Leedy", "author_id": 8554, "author_profile": "https://wordpress.stackexchange.com/users/8554", "pm_score": 2, "selected": false, "text": "<p>According to that Codex page, you need to use <code>menu_id</code>. <code>container_id</code> only effects ...
2013/01/11
[ "https://wordpress.stackexchange.com/questions/80158", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/3206/" ]
The following code does not produce a UL with ID of "nav". It just produces ``` <div class="menu"><ul> ``` This is the code: ``` wp_nav_menu( array( 'theme_location' => 'menu-1', 'container_id' => 'nav'; ``` According the [WP Codex](http://codex.wordpress.org/Function_Reference/wp_nav_menu) this should work....
According to that Codex page, you need to use `menu_id`. `container_id` only effects the surrounding div.
80,164
<p>I'm trying to build kind of a filtering system for the events displayed on my website. I've made a custom post type 'Event', with a 'City' field. On my 'calendar' template page, I'm gathering all the events like this : </p> <pre><code>$querystr = " SELECT * FROM $wpdb-&gt;posts wposts, $wpdb-&gt;postmeta me...
[ { "answer_id": 80171, "author": "Mike Madern", "author_id": 24806, "author_profile": "https://wordpress.stackexchange.com/users/24806", "pm_score": 0, "selected": false, "text": "<p>AJAX definitely will be the right choice for you.</p>\n\n<p><a href=\"http://wp.tutsplus.com/articles/gett...
2013/01/11
[ "https://wordpress.stackexchange.com/questions/80164", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25888/" ]
I'm trying to build kind of a filtering system for the events displayed on my website. I've made a custom post type 'Event', with a 'City' field. On my 'calendar' template page, I'm gathering all the events like this : ``` $querystr = " SELECT * FROM $wpdb->posts wposts, $wpdb->postmeta metastart WHERE wp...
Yes, if you need to run WordPress/PHP functions from a button click (Javascript), you need Ajax. In the following example, a shortcode will render a button (`id="newquote"`) that calls an Ajax action hook (`get_random_cpt`). A query is done and replaces one div from that shortcode (`id="randomquotes"`) with the result...
80,174
<p><strong>Hi</strong> Im trying to run 2 querys in the same query call.</p> <pre><code> // send the query global $wpdb; $commentQ = "SELECT * FROM $wpdb-&gt;comments " . $whereClause . $orderBy; $comments = $wpdb-&gt;get_results( $commentQ, ARRAY_A); </code></pre> <p>So far it works , but when i try to run 2...
[ { "answer_id": 82645, "author": "s_ha_dum", "author_id": 21376, "author_profile": "https://wordpress.stackexchange.com/users/21376", "pm_score": 2, "selected": true, "text": "<p>If you are going to do this is SQL, use a subquery.</p>\n\n<pre><code>SELECT *,\n (SELECT meta_value \n FR...
2013/01/11
[ "https://wordpress.stackexchange.com/questions/80174", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/21256/" ]
**Hi** Im trying to run 2 querys in the same query call. ``` // send the query global $wpdb; $commentQ = "SELECT * FROM $wpdb->comments " . $whereClause . $orderBy; $comments = $wpdb->get_results( $commentQ, ARRAY_A); ``` So far it works , but when i try to run 2 querys it fails. What I wanna do is i want t...
If you are going to do this is SQL, use a subquery. ``` SELECT *, (SELECT meta_value FROM wp_commentmeta WHERE meta_key = 'your-meta-key' AND wp_commentmeta.comment_id = wp_comments.comment_ID LIMIT 1) as comment_author FROM wp_comments ``` Instead of the `*`, enumerate the fields you want but leav...
80,193
<p>I'm new here and my english isn't perfect so I'm sorry for this :) I'm here because I'm workin on site with post list sorted by category and I have problem with sort out my posts in categories and children categories under them. Now everything is messed up. I would like to sort my custom posts like that:</p> <p>CA...
[ { "answer_id": 80291, "author": "OriginalEXE", "author_id": 16710, "author_profile": "https://wordpress.stackexchange.com/users/16710", "pm_score": 0, "selected": false, "text": "<p>I played a little and this is what I came up with, I tested and it works just like your given example:</p>...
2013/01/11
[ "https://wordpress.stackexchange.com/questions/80193", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25892/" ]
I'm new here and my english isn't perfect so I'm sorry for this :) I'm here because I'm workin on site with post list sorted by category and I have problem with sort out my posts in categories and children categories under them. Now everything is messed up. I would like to sort my custom posts like that: CATEGORY 1 *...
ok, this is my working solution: ``` <?php $args=array( 'post_type' => 'biblioteka', 'child_of' => 0, 'parent' => '', 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 1, 'hierarchical' => 1, 'exclude' ...
80,215
<p>I want to add a simple confirmation event to the Publish posts button, so when my client hits "Publish" it will ask him if he's sure, to which he clicks "Yes" or "cancel" and the post then publishes or doesn't.</p> <p>I'm new to WordPress...or at least I've only done theme and limited plugin programming. I did fin...
[ { "answer_id": 80217, "author": "diggy", "author_id": 25765, "author_profile": "https://wordpress.stackexchange.com/users/25765", "pm_score": 0, "selected": false, "text": "<p>There's a WordPress plugin for that: </p>\n\n<blockquote>\n <p><a href=\"http://wordpress.org/extend/plugins/co...
2013/01/11
[ "https://wordpress.stackexchange.com/questions/80215", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/8279/" ]
I want to add a simple confirmation event to the Publish posts button, so when my client hits "Publish" it will ask him if he's sure, to which he clicks "Yes" or "cancel" and the post then publishes or doesn't. I'm new to WordPress...or at least I've only done theme and limited plugin programming. I did find the metab...
You can hook into the post footer actions (based on [this answer](https://wordpress.stackexchange.com/questions/73692/add-script-to-footer-on-post-editor/73693#73693), not tested): ``` add_action( 'admin_footer-post-new.php', 'wpse_80215_script' ); add_action( 'admin_footer-post.php', 'wpse_80215_script' ); function ...
80,234
<p>Is there a tool to connect the databases of 2 sites sitting on separate networks with one login allowing them to share a common user base?</p> <p>I have searched around, but I unable to find a clear answer or a way to be done.</p>
[ { "answer_id": 80217, "author": "diggy", "author_id": 25765, "author_profile": "https://wordpress.stackexchange.com/users/25765", "pm_score": 0, "selected": false, "text": "<p>There's a WordPress plugin for that: </p>\n\n<blockquote>\n <p><a href=\"http://wordpress.org/extend/plugins/co...
2013/01/11
[ "https://wordpress.stackexchange.com/questions/80234", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25277/" ]
Is there a tool to connect the databases of 2 sites sitting on separate networks with one login allowing them to share a common user base? I have searched around, but I unable to find a clear answer or a way to be done.
You can hook into the post footer actions (based on [this answer](https://wordpress.stackexchange.com/questions/73692/add-script-to-footer-on-post-editor/73693#73693), not tested): ``` add_action( 'admin_footer-post-new.php', 'wpse_80215_script' ); add_action( 'admin_footer-post.php', 'wpse_80215_script' ); function ...
80,238
<p>For each new post, I add <code>News</code> category.</p> <p>And I want to <code>delete this category</code> from each post after 7 days. I already know to "delete" the new category but how to run it every week ? </p>
[ { "answer_id": 80240, "author": "OriginalEXE", "author_id": 16710, "author_profile": "https://wordpress.stackexchange.com/users/16710", "pm_score": 3, "selected": true, "text": "<p>Did you try this plugin? \n<a href=\"http://wordpress.org/extend/plugins/scheduled-post-delete/\" rel=\"nof...
2013/01/11
[ "https://wordpress.stackexchange.com/questions/80238", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/2000/" ]
For each new post, I add `News` category. And I want to `delete this category` from each post after 7 days. I already know to "delete" the new category but how to run it every week ?
Did you try this plugin? <http://wordpress.org/extend/plugins/scheduled-post-delete/> //// Sorry for my mistake, I understood you wrong. Try by pasting this in your functions.php: ``` function auto_cat_remove() { global $post; wp_schedule_single_event( time() + 604800, 'remove_news_cat_event', array( $post...
80,256
<p>how can I create a widget out of a php code? It's just a disqus code that I would like to place in the sidebar. I could just paste the code in the widget section (my tag), but then I would not be able to change it's order with the other wigets. This is why I want to convert this code into a widget.</p>
[ { "answer_id": 80258, "author": "PrivateUser", "author_id": 5074, "author_profile": "https://wordpress.stackexchange.com/users/5074", "pm_score": 0, "selected": false, "text": "<p>Use this plugin, <a href=\"http://wordpress.org/extend/plugins/php-code-widget/\" rel=\"nofollow\">PHP Code ...
2013/01/12
[ "https://wordpress.stackexchange.com/questions/80256", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/-1/" ]
how can I create a widget out of a php code? It's just a disqus code that I would like to place in the sidebar. I could just paste the code in the widget section (my tag), but then I would not be able to change it's order with the other wigets. This is why I want to convert this code into a widget.
Here is a stand-alone answer. Building a widget to echo hard-coded PHP is trivial. ``` class PHP_Widget_wpse_80256 extends WP_Widget { function __construct() { $opts = array( 'description' => 'Display Some Hard Coded PHP content' ); parent::WP_Widget( 'my-hc-php-content', 'Some PHP', ...
80,260
<p>I followed <a href="http://codegarage.com/blog/2009/03/creating-user-friendly-custom-fields-by-modifying-the-post-page/comment-page-1/" rel="nofollow">this tutorial</a> to create a custom meta box with a simple two option drop down. </p> <p>My code is below. The custom fields are saved when creating a post, and edi...
[ { "answer_id": 80258, "author": "PrivateUser", "author_id": 5074, "author_profile": "https://wordpress.stackexchange.com/users/5074", "pm_score": 0, "selected": false, "text": "<p>Use this plugin, <a href=\"http://wordpress.org/extend/plugins/php-code-widget/\" rel=\"nofollow\">PHP Code ...
2013/01/12
[ "https://wordpress.stackexchange.com/questions/80260", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/10413/" ]
I followed [this tutorial](http://codegarage.com/blog/2009/03/creating-user-friendly-custom-fields-by-modifying-the-post-page/comment-page-1/) to create a custom meta box with a simple two option drop down. My code is below. The custom fields are saved when creating a post, and edit when I change the value and Update...
Here is a stand-alone answer. Building a widget to echo hard-coded PHP is trivial. ``` class PHP_Widget_wpse_80256 extends WP_Widget { function __construct() { $opts = array( 'description' => 'Display Some Hard Coded PHP content' ); parent::WP_Widget( 'my-hc-php-content', 'Some PHP', ...
80,270
<p>In a nutshell, my question is "How do I convert the absolute path of the executing script, e.g.,</p> <pre><code>/home/content/xx/xxxxxxxx/html/wp-content/plugins/MY_PLUGIN_DIR/MY_PLUGIN/MY_PLUGIN.PHP </code></pre> <p>or</p> <pre><code>/home/content/xx/xxxxxxxx/html/wp-content/themes/MY_THEME/functions.php </code>...
[ { "answer_id": 80272, "author": "webaware", "author_id": 24260, "author_profile": "https://wordpress.stackexchange.com/users/24260", "pm_score": 2, "selected": true, "text": "<p>Call <a href=\"http://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri\" rel=\"nofollow\">g...
2013/01/12
[ "https://wordpress.stackexchange.com/questions/80270", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25472/" ]
In a nutshell, my question is "How do I convert the absolute path of the executing script, e.g., ``` /home/content/xx/xxxxxxxx/html/wp-content/plugins/MY_PLUGIN_DIR/MY_PLUGIN/MY_PLUGIN.PHP ``` or ``` /home/content/xx/xxxxxxxx/html/wp-content/themes/MY_THEME/functions.php ``` to the absolute URL?" ``` http://exam...
Call [get\_stylesheet\_directory\_uri()](http://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri) for the current theme, or [get\_template\_directory\_uri()](http://codex.wordpress.org/Function_Reference/get_template_directory_uri) for the parent theme of a child theme, and append your file paths to ...
80,274
<p>I am trying to add the custom page template selector that can be found in the "edit page" screen for pages to a custom taxonomy. The custom taxonomy is product_cat created by WooCommerce. </p> <p>I am using the Tax-meta-class created by Ohad Raz of en.bainternet.info. This allows me to add a meta box to the the "ed...
[ { "answer_id": 80317, "author": "Milo", "author_id": 4771, "author_profile": "https://wordpress.stackexchange.com/users/4771", "pm_score": 0, "selected": false, "text": "<p><a href=\"http://codex.wordpress.org/Function_Reference/get_page_templates\" rel=\"nofollow\"><code>get_page_templa...
2013/01/12
[ "https://wordpress.stackexchange.com/questions/80274", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25927/" ]
I am trying to add the custom page template selector that can be found in the "edit page" screen for pages to a custom taxonomy. The custom taxonomy is product\_cat created by WooCommerce. I am using the Tax-meta-class created by Ohad Raz of en.bainternet.info. This allows me to add a meta box to the the "edit produc...
[`get_page_templates`](http://codex.wordpress.org/Function_Reference/get_page_templates) already returns an array: ``` Array ( [Sidebar] => sidebar.php [Category] => category.php [Page] => page.php ) ``` If you need to swap keys and values you can use php's [`array_flip`](http://www.php.net/manual/en/fun...
80,296
<p>I am trying to make a custum 'Recent Comments' code for use in the sidebar. I have come a long way, but there is just one thing that doesn't do what I'd like it to do.</p> <p>What I want is that, per page with comments that is found, only the last comment is shown. I was hoping post_per_page would do the trick, but...
[ { "answer_id": 80298, "author": "s_ha_dum", "author_id": 21376, "author_profile": "https://wordpress.stackexchange.com/users/21376", "pm_score": 3, "selected": true, "text": "<p>Unless you are working on WordPress core development you should not be writing anything but a:</p>\n\n<ol>\n<l...
2013/01/12
[ "https://wordpress.stackexchange.com/questions/80296", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25936/" ]
I am trying to make a custum 'Recent Comments' code for use in the sidebar. I have come a long way, but there is just one thing that doesn't do what I'd like it to do. What I want is that, per page with comments that is found, only the last comment is shown. I was hoping post\_per\_page would do the trick, but it does...
Unless you are working on WordPress core development you should not be writing anything but a: 1. Theme 2. Child Theme 3. Plugin 4. Mu-Plugin 5. Drop-In For the last two see: <http://hakre.wordpress.com/2010/05/01/must-use-and-drop-ins-plugins/> I am out on a limb a little bit here but I think that is the exhaustive...
80,303
<p>I am trying to get a query to retrieve all the posts where a specific <code>meta_key</code> does not exist and then create it.</p> <p>I am having problems finding those posts as the query I am testing does not seem to work. </p> <p>Here is the code I am using to try to get those posts:</p> <pre><code>$args = arra...
[ { "answer_id": 81831, "author": "Tomas Buteler", "author_id": 5552, "author_profile": "https://wordpress.stackexchange.com/users/5552", "pm_score": 8, "selected": true, "text": "<p>I did some more testing with this, and honestly can't find a reason it wouldn't work (unless the code above...
2013/01/12
[ "https://wordpress.stackexchange.com/questions/80303", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/8918/" ]
I am trying to get a query to retrieve all the posts where a specific `meta_key` does not exist and then create it. I am having problems finding those posts as the query I am testing does not seem to work. Here is the code I am using to try to get those posts: ``` $args = array( 'posts_per_page' => 18, 'cat'=...
I did some more testing with this, and honestly can't find a reason it wouldn't work (unless the code above is just a snippet and the real code fits on my examples below). I did, however, discover a couple of things that might lead you in the right direction. 1) By itself, this meta query is the equivalent of "colors ...
80,334
<p>What is the best way create a plugin that is translation ready? </p> <p>It doesn't have to be translated from the beginning but it has to be easily translatable so fellow developers from different cultures can participate to the localization process of the plugin. </p>
[ { "answer_id": 80335, "author": "Nabil Kadimi", "author_id": 17187, "author_profile": "https://wordpress.stackexchange.com/users/17187", "pm_score": 6, "selected": true, "text": "<h1>1. Write with localization in mind</h1>\n\n<p>Don't use <code>echo</code> or <code>print()</code> to prod...
2013/01/12
[ "https://wordpress.stackexchange.com/questions/80334", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/17187/" ]
What is the best way create a plugin that is translation ready? It doesn't have to be translated from the beginning but it has to be easily translatable so fellow developers from different cultures can participate to the localization process of the plugin.
1. Write with localization in mind ================================== Don't use `echo` or `print()` to produce text output, instead use the WordPress functions `__()` and `_e()`: ```php /** Not localization friendly */ echo "Welcome to my plugin"; // OR print("Welcome to my plugin"); /** Localization friendly */...
80,343
<p>How can I list the authors of posts in a category in WordPress?</p> <p>On my blog have three authors and I want to list who written the posts in a category. For example:</p> <pre><code>CAT NAME: INTERNET AUTHOR: JOHN, DOE, ALEX CAT NAME: TECH AUTHOR: JOHN CAT NAME: CODE AUTHOR: ALEX </code></pr...
[ { "answer_id": 80358, "author": "JCL1178", "author_id": 6146, "author_profile": "https://wordpress.stackexchange.com/users/6146", "pm_score": 1, "selected": false, "text": "<p>WordPress Categories don't have authors in the traditional sense of the term. You should read up on the <a href...
2013/01/13
[ "https://wordpress.stackexchange.com/questions/80343", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25951/" ]
How can I list the authors of posts in a category in WordPress? On my blog have three authors and I want to list who written the posts in a category. For example: ``` CAT NAME: INTERNET AUTHOR: JOHN, DOE, ALEX CAT NAME: TECH AUTHOR: JOHN CAT NAME: CODE AUTHOR: ALEX ```
I found a solution. CODE: ``` <?php $cat_arr = get_categories(); // Get the list of Categories foreach ($cat_arr as $cat_obj) { $term_id = $cat_obj->term_id; // Print the Name ?> <br> CAT NAME: <?php echo $cat_obj->name ?>, AUTHOR: <?php // Get all P...
80,345
<p>Not sure if "sanitizing" is really the correct phrase to use for this but it was the best one I could think of...anyways, here is the problem:</p> <p>My function works great like so...</p> <pre><code>// add category id to body &amp; post classes function category_id_class($classes) { global $post; foreach...
[ { "answer_id": 80346, "author": "akTed", "author_id": 25472, "author_profile": "https://wordpress.stackexchange.com/users/25472", "pm_score": 1, "selected": false, "text": "<p><a href=\"http://codex.wordpress.org/Function_Reference/sanitize_title_with_dashes\" rel=\"nofollow\">sanitize_t...
2013/01/13
[ "https://wordpress.stackexchange.com/questions/80345", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/3567/" ]
Not sure if "sanitizing" is really the correct phrase to use for this but it was the best one I could think of...anyways, here is the problem: My function works great like so... ``` // add category id to body & post classes function category_id_class($classes) { global $post; foreach((get_the_category($post-...
Just use `$category->slug` instead of `$category->cat_name`. Slugs are already lowercase and with dashes instead of spaces.
80,347
<p>Is there any way to display a user's (registered) registration date on the comment.</p> <p>Lets say i have a written an article, registered users A, B, C and D left a comment on my article.</p> <p>I can display comment date, commenter's name and email by default .</p> <p>I want to display the commenter's regis...
[ { "answer_id": 80348, "author": "s_ha_dum", "author_id": 21376, "author_profile": "https://wordpress.stackexchange.com/users/21376", "pm_score": 0, "selected": false, "text": "<p>All the information you need is in the user Object pulled by <a href=\"http://codex.wordpress.org/Function_Re...
2013/01/13
[ "https://wordpress.stackexchange.com/questions/80347", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25952/" ]
Is there any way to display a user's (registered) registration date on the comment. Lets say i have a written an article, registered users A, B, C and D left a comment on my article. I can display comment date, commenter's name and email by default . I want to display the commenter's registration date also. How ca...
In your [`wp_list_comments`](http://codex.wordpress.org/Function_Reference/wp_list_comments) callback function, you can call [`get_userdata`](http://codex.wordpress.org/Function_Reference/get_userdata) to get any additional comment author data: ``` $userdata = get_userdata( $comment->user_id ); echo 'Registered: ' . $...
80,357
<p>I'm writing a plugin to add some extra contents that contain the permanent link to the (single) post. </p> <pre><code>function abcd_add_contents($content) { $extra_content = the_permalink(); if (is_single()) { $content .= $extra_content; } return $content; } add_filter('the_content', 'abc...
[ { "answer_id": 80359, "author": "Milo", "author_id": 4771, "author_profile": "https://wordpress.stackexchange.com/users/4771", "pm_score": 3, "selected": true, "text": "<p>globalize <code>$post</code> to get the current post's data. also, you want <code>get_permalink</code>, which <em>re...
2013/01/13
[ "https://wordpress.stackexchange.com/questions/80357", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/14571/" ]
I'm writing a plugin to add some extra contents that contain the permanent link to the (single) post. ``` function abcd_add_contents($content) { $extra_content = the_permalink(); if (is_single()) { $content .= $extra_content; } return $content; } add_filter('the_content', 'abcd_add_contents...
globalize `$post` to get the current post's data. also, you want `get_permalink`, which *returns* the permalink, rather than `the_permalink`, which directly *echoes* the permalink. ``` function abcd_add_contents($content) { if (is_single()) { global $post; $extra_content = get_permalink( $post->ID...
80,387
<p>I've created a custom <code>content.php</code> and removed any comments on the <code>content.php</code> page</p> <p>then i changed the <code>sharing-service.php</code> from jetpack and added <code>comments_popup_link</code> there:</p> <pre><code>// Wrapper $sharing_content .= '&lt;div class="sharedaddy sd-sharing-...
[ { "answer_id": 80389, "author": "diggy", "author_id": 25765, "author_profile": "https://wordpress.stackexchange.com/users/25765", "pm_score": 1, "selected": false, "text": "<p>As @Michael points out, \"<code>comments_popup_link()</code> prints the result, and can therefore not be used in...
2013/01/13
[ "https://wordpress.stackexchange.com/questions/80387", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25945/" ]
I've created a custom `content.php` and removed any comments on the `content.php` page then i changed the `sharing-service.php` from jetpack and added `comments_popup_link` there: ``` // Wrapper $sharing_content .= '<div class="sharedaddy sd-sharing-enabled">'; $sharing_content .= '<div class="robots-nocontent sd-blo...
You could probably just buffer the output from comments\_popup\_link in a separate function. ``` function get_comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) { ob_start(); comments_popup_link( $zero, $one, $more, $css_class, $none ); return ob_get_clean(); ...
80,388
<p>I am trying to post to the loop.php template file and it is not going through for some reason, usually it should work but it isnt. Is there a alternative way to get this done?</p> <p>This is what I have in the index.php file of the theme.</p> <pre><code>$('.load_more_cont a').live('click', function(e) { ...
[ { "answer_id": 80389, "author": "diggy", "author_id": 25765, "author_profile": "https://wordpress.stackexchange.com/users/25765", "pm_score": 1, "selected": false, "text": "<p>As @Michael points out, \"<code>comments_popup_link()</code> prints the result, and can therefore not be used in...
2013/01/13
[ "https://wordpress.stackexchange.com/questions/80388", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/7924/" ]
I am trying to post to the loop.php template file and it is not going through for some reason, usually it should work but it isnt. Is there a alternative way to get this done? This is what I have in the index.php file of the theme. ``` $('.load_more_cont a').live('click', function(e) { leftwrapper = 'THIS...
You could probably just buffer the output from comments\_popup\_link in a separate function. ``` function get_comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) { ob_start(); comments_popup_link( $zero, $one, $more, $css_class, $none ); return ob_get_clean(); ...
80,408
<p>I am trying to retrieve all the images from the <code>Gallery</code> of a page in the order they are set in the backend.</p> <p>So far I have:</p> <pre><code> $my_wp_query = new WP_Query(); $all_wp_pages = $my_wp_query-&gt;query( array( 'post_type' =&gt; 'attachment', 'post_parent' =&gt; 54, ...
[ { "answer_id": 80413, "author": "Steve", "author_id": 23132, "author_profile": "https://wordpress.stackexchange.com/users/23132", "pm_score": 0, "selected": false, "text": "<pre><code>$oImages = get_posts(\n array(\n 'numberposts' =&gt; -1,\n 'post_parent' =&gt; $post-...
2013/01/13
[ "https://wordpress.stackexchange.com/questions/80408", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/16467/" ]
I am trying to retrieve all the images from the `Gallery` of a page in the order they are set in the backend. So far I have: ``` $my_wp_query = new WP_Query(); $all_wp_pages = $my_wp_query->query( array( 'post_type' => 'attachment', 'post_parent' => 54, 'post_mime_type' =>'image', '...
When you create a gallery via the 3.5 media manager, `menu_order` is no longer used to save the order of the images, the order only exists in the shortcode you insert when you click the `Insert Gallery` button, via the `ids=` attribute. This is to accommodate the fact that you can now add multiple galleries to a single...
80,414
<p>I am working on a simple search form widget, with a built in autocomplete capability (You can download the current version <a href="http://wordpress.org/extend/plugins/wd-search-form/">here</a>). The plugin is working, but I am currently rewriting all the code using OOP. One of the problems I came across was the fac...
[ { "answer_id": 80415, "author": "Steve", "author_id": 23132, "author_profile": "https://wordpress.stackexchange.com/users/23132", "pm_score": 4, "selected": true, "text": "<p>You can simply put your init code within the constructor of the class. For example:</p>\n\n<pre><code>class myWid...
2013/01/13
[ "https://wordpress.stackexchange.com/questions/80414", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25959/" ]
I am working on a simple search form widget, with a built in autocomplete capability (You can download the current version [here](http://wordpress.org/extend/plugins/wd-search-form/)). The plugin is working, but I am currently rewriting all the code using OOP. One of the problems I came across was the fact the a Wordpr...
You can simply put your init code within the constructor of the class. For example: ``` class myWidget extends WP_Widget{ function myWidget(){ // Init code here } function widget( $args, $instance ) { // The widget code wp_enqueue_script(...); wp_enqueue_style(...); } ...
80,418
<p>In the code below, unless I hardcode a reference to the jQuery library, my jQuery bits on the page do not work. What's wrong with the enqueue method I'm trying to use?</p> <p>In functions.php:</p> <pre><code>if(is_admin()) { /* LOAD ADMIN SCRIPTS **********************************/ require_once(TEMPLATEPATH . '/f...
[ { "answer_id": 80424, "author": "Muhammad Furqan", "author_id": 25586, "author_profile": "https://wordpress.stackexchange.com/users/25586", "pm_score": 0, "selected": false, "text": "<p>WordPress jQuery does not support $ by default.</p>\n\n<p>First Add jQuery.</p>\n\n<pre><code>function...
2013/01/13
[ "https://wordpress.stackexchange.com/questions/80418", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/366/" ]
In the code below, unless I hardcode a reference to the jQuery library, my jQuery bits on the page do not work. What's wrong with the enqueue method I'm trying to use? In functions.php: ``` if(is_admin()) { /* LOAD ADMIN SCRIPTS **********************************/ require_once(TEMPLATEPATH . '/functions_private.php'...
Use the `admin_enqueue_scripts` hook to add your own custom script. Put it in an external file, and use `wp_localize_script` to pass any data from php to javascript. jQuery is already used on the admin side, adding a script tag sourcing it from google will break things. ``` function wpa80418_admin_enqueue( $hook ) { ...
80,422
<p>I have a custom-built website which pulls data from WordPress.</p> <p>I've included <code>wp-blog-header.php</code> in my page and it is all set, I can get my posts, featured image, titles, anything I want, wherever I want.</p> <p>Now I'd like to add new languages to my website, so I've set up multisite so I can h...
[ { "answer_id": 80436, "author": "Mark Kaplun", "author_id": 23970, "author_profile": "https://wordpress.stackexchange.com/users/23970", "pm_score": 0, "selected": false, "text": "<p>In almost the same way, you just need to set <code>$_SERVER['REQUEST_URI']</code> to the URL which you wou...
2013/01/13
[ "https://wordpress.stackexchange.com/questions/80422", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25306/" ]
I have a custom-built website which pulls data from WordPress. I've included `wp-blog-header.php` in my page and it is all set, I can get my posts, featured image, titles, anything I want, wherever I want. Now I'd like to add new languages to my website, so I've set up multisite so I can have one site for each langua...
You can use the [`switch_to_blog()`](http://codex.wordpress.org/Function_Reference/switch_to_blog) function to switch the scope to a specific site and access data from that site: ``` require_once( '/path/to/wp-load.php' ); switch_to_blog( 3 ); $option = get_option( 'admin_email' ); restore_current_blog(); ``` Also, ...
80,434
<p>How can I just show the post content in a search result? Currently, the search results displays the post title, author and date above the page content.</p> <p>Here is how it looks now: <a href="http://sikkervaccination.dk/?s=thailand" rel="nofollow">http://sikkervaccination.dk/?s=thailand</a></p>
[ { "answer_id": 80435, "author": "Mateusz Hajdziony", "author_id": 15865, "author_profile": "https://wordpress.stackexchange.com/users/15865", "pm_score": 0, "selected": false, "text": "<p>You can usually modify the display of your search results by editing a loop in <code>search.php</cod...
2013/01/13
[ "https://wordpress.stackexchange.com/questions/80434", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25745/" ]
How can I just show the post content in a search result? Currently, the search results displays the post title, author and date above the page content. Here is how it looks now: <http://sikkervaccination.dk/?s=thailand>
Some themes like Twenty Fourteen include a template tag included in the content.php file for entry meta which includes the author and date: Example: ``` twentyfourteen_posted_on(); ``` The content.php file also includes [`the_title()`](http://codex.wordpress.org/Function_Reference/the_title) tag so you need to remo...
80,439
<p>I am using the below to fetch the content of a page by its name and output the html</p> <pre><code> $my_wp_query = new WP_Query(); $page = $my_wp_query-&gt;query( array( 'post_type' =&gt; 'page', 'name' =&gt; 'some-page-slug' ) ); $page = $page[0]; $page_data['content'] = apply_filter...
[ { "answer_id": 80440, "author": "s_ha_dum", "author_id": 21376, "author_profile": "https://wordpress.stackexchange.com/users/21376", "pm_score": 3, "selected": true, "text": "<p>I may be misinterpreting you, but I think what you want to do is run through <a href=\"http://codex.wordpress....
2013/01/14
[ "https://wordpress.stackexchange.com/questions/80439", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/16467/" ]
I am using the below to fetch the content of a page by its name and output the html ``` $my_wp_query = new WP_Query(); $page = $my_wp_query->query( array( 'post_type' => 'page', 'name' => 'some-page-slug' ) ); $page = $page[0]; $page_data['content'] = apply_filters('the_content', $page-...
I may be misinterpreting you, but I think what you want to do is run through [`strip_shortcodes`](http://codex.wordpress.org/Function_Reference/strip_shortcodes) ``` $page_data['content'] = strip_shortcodes($page->post_content); $page_data['content'] = apply_filters('the_content', $page_data['content']); ``` Alt...
80,455
<p>I've recently discovered that we can insert a dropdown list of categories like this:</p> <pre><code>define( 'WP_USE_THEMES', false ); require( './wp-load.php' ); wp_dropdown_categories( array( 'child_of' =&gt; 0, 'class' =&gt; 'postform', 'depth' =&gt; 0, 'echo' ...
[ { "answer_id": 81600, "author": "Sweepster", "author_id": 10507, "author_profile": "https://wordpress.stackexchange.com/users/10507", "pm_score": 3, "selected": true, "text": "<p>Here is the answer I ended up with:</p>\n\n<pre><code>$select_cats = wp_dropdown_categories( array( 'echo' =&...
2013/01/14
[ "https://wordpress.stackexchange.com/questions/80455", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/10507/" ]
I've recently discovered that we can insert a dropdown list of categories like this: ``` define( 'WP_USE_THEMES', false ); require( './wp-load.php' ); wp_dropdown_categories( array( 'child_of' => 0, 'class' => 'postform', 'depth' => 0, 'echo' => 1, 'exclud...
Here is the answer I ended up with: ``` $select_cats = wp_dropdown_categories( array( 'echo' => 0 ) ); $select_cats = str_replace( "name='cat' id=", "name='cat[]' multiple='multiple' id=", $select_cats ); echo $select_cats; ``` It displays a list of my categories that can be multi-selected as per my question. It's a...
80,457
<p>I know this may be a bit crazy, and hopefully there's a way of doing this with out chopping up the core. </p> <p>I am trying to clean up my Wordpress admin menu's and in doing such I'd like to move Comments under Posts. The problem is obouvisly edit-comments.php is a main menu item and not a sub-menu item. </p> <p...
[ { "answer_id": 81600, "author": "Sweepster", "author_id": 10507, "author_profile": "https://wordpress.stackexchange.com/users/10507", "pm_score": 3, "selected": true, "text": "<p>Here is the answer I ended up with:</p>\n\n<pre><code>$select_cats = wp_dropdown_categories( array( 'echo' =&...
2013/01/14
[ "https://wordpress.stackexchange.com/questions/80457", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/24301/" ]
I know this may be a bit crazy, and hopefully there's a way of doing this with out chopping up the core. I am trying to clean up my Wordpress admin menu's and in doing such I'd like to move Comments under Posts. The problem is obouvisly edit-comments.php is a main menu item and not a sub-menu item. I know you can m...
Here is the answer I ended up with: ``` $select_cats = wp_dropdown_categories( array( 'echo' => 0 ) ); $select_cats = str_replace( "name='cat' id=", "name='cat[]' multiple='multiple' id=", $select_cats ); echo $select_cats; ``` It displays a list of my categories that can be multi-selected as per my question. It's a...
81,480
<p>Another user on here suggested that my use of queries was incorrect so I'm changing the code. However, the pagination in the first block of code (below) isn't showing up in the HTML while the second one (my original) shows up fine.</p> <p>This one doesn't work (new code):</p> <pre><code> $paged ...
[ { "answer_id": 81497, "author": "Tom J Nowell", "author_id": 736, "author_profile": "https://wordpress.stackexchange.com/users/736", "pm_score": 3, "selected": true, "text": "<p>Rather than attempt to fix your query, I recommend you sidestep it entirely by using custom post type archives...
2013/01/14
[ "https://wordpress.stackexchange.com/questions/81480", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18320/" ]
Another user on here suggested that my use of queries was incorrect so I'm changing the code. However, the pagination in the first block of code (below) isn't showing up in the HTML while the second one (my original) shows up fine. This one doesn't work (new code): ``` $paged = (get_query_var('pag...
Rather than attempt to fix your query, I recommend you sidestep it entirely by using custom post type archives! With permalinks on, you should be able to view a list of all your movies posts by going to: ``` example.com/movies ``` Then, in your theme, create `archive-movies.php`, and it will be used instead of the ...
81,486
<p>I have a wordpress blog. I get url in blog like this,</p> <pre><code> http://www.domain.com/2013/01/test19/page/2/ </code></pre> <p>But I want my ur like this,</p> <pre><code> http://www.domain.com/page/2/ </code></pre> <p>So can we rewrite this url. I am newbie to .htaccess. I search many plugins like "WP ...
[ { "answer_id": 81497, "author": "Tom J Nowell", "author_id": 736, "author_profile": "https://wordpress.stackexchange.com/users/736", "pm_score": 3, "selected": true, "text": "<p>Rather than attempt to fix your query, I recommend you sidestep it entirely by using custom post type archives...
2013/01/14
[ "https://wordpress.stackexchange.com/questions/81486", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25856/" ]
I have a wordpress blog. I get url in blog like this, ``` http://www.domain.com/2013/01/test19/page/2/ ``` But I want my ur like this, ``` http://www.domain.com/page/2/ ``` So can we rewrite this url. I am newbie to .htaccess. I search many plugins like "WP htaccess control". But I dont know how to configu...
Rather than attempt to fix your query, I recommend you sidestep it entirely by using custom post type archives! With permalinks on, you should be able to view a list of all your movies posts by going to: ``` example.com/movies ``` Then, in your theme, create `archive-movies.php`, and it will be used instead of the ...
81,491
<p>I'd like to change the default country on the <strong>cart</strong> page to <em>none</em>, i.e. to have "Select a country…" appear as the default in the drop-down list of countries.</p> <p>I've looked at <a href="http://wcdocs.woothemes.com/snippets/change-the-default-state-and-country-on-the-checkout/" rel="nofoll...
[ { "answer_id": 84507, "author": "mroncetwice", "author_id": 13424, "author_profile": "https://wordpress.stackexchange.com/users/13424", "pm_score": 1, "selected": false, "text": "<p>By chance and just plain putzing around, I've come up with this:</p>\n\n<pre><code>add_filter( 'woocommerc...
2013/01/14
[ "https://wordpress.stackexchange.com/questions/81491", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/16352/" ]
I'd like to change the default country on the **cart** page to *none*, i.e. to have "Select a country…" appear as the default in the drop-down list of countries. I've looked at [this WooCommerce Docs snippet](http://wcdocs.woothemes.com/snippets/change-the-default-state-and-country-on-the-checkout/) which uses the `de...
I have same issue, but need to set country to US, here is how I fix it: ``` add_action('woocommerce_add_to_cart' , 'set_country_befor_cart_page'); function set_country_befor_cart_page(){ WC()->customer->set_billing_country('US'); WC()->customer->set_shipping_country('US'); } ``` Hope it will help.
81,501
<pre><code>&lt;?php if ( ! is_admin() ) return; echo 'You should not see this if you\'re not logged in!'; ?&gt; </code></pre> <p>If you put this in a <a href="http://codex.wordpress.org/Must_Use_Plugins" rel="nofollow">mu-plugin</a>, and go to your admin, e.g., <code>example.com/wp-admin/</code> while you are <em>not ...
[ { "answer_id": 81508, "author": "amit", "author_id": 17968, "author_profile": "https://wordpress.stackexchange.com/users/17968", "pm_score": 2, "selected": false, "text": "<blockquote>\n <p><em>The <a href=\"http://codex.wordpress.org/Function_Reference/is_admin\" rel=\"nofollow\"><code...
2013/01/14
[ "https://wordpress.stackexchange.com/questions/81501", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25472/" ]
``` <?php if ( ! is_admin() ) return; echo 'You should not see this if you\'re not logged in!'; ?> ``` If you put this in a [mu-plugin](http://codex.wordpress.org/Must_Use_Plugins), and go to your admin, e.g., `example.com/wp-admin/` while you are *not logged in*, should you be able to see the `echo`?
You're misinterpreting the `is_admin()` function. It's not a tag to check whether or not the *user* is an admin, it's a template tag to check if you're on an admin page. From the [Codex](http://codex.wordpress.org/Function_Reference/is_admin): > > This Conditional Tag checks if the Dashboard or the administration pa...
81,512
<p>Bare with me as I explain this. I'm adding an Assistant Editor feature to my multiple author platform. In the box that appears in post-edit page, the Editors can tick which task that they have done (for instance proofread the article) and then check their username (so that they will be credited on the front post pag...
[ { "answer_id": 81508, "author": "amit", "author_id": 17968, "author_profile": "https://wordpress.stackexchange.com/users/17968", "pm_score": 2, "selected": false, "text": "<blockquote>\n <p><em>The <a href=\"http://codex.wordpress.org/Function_Reference/is_admin\" rel=\"nofollow\"><code...
2013/01/14
[ "https://wordpress.stackexchange.com/questions/81512", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/24875/" ]
Bare with me as I explain this. I'm adding an Assistant Editor feature to my multiple author platform. In the box that appears in post-edit page, the Editors can tick which task that they have done (for instance proofread the article) and then check their username (so that they will be credited on the front post page)....
You're misinterpreting the `is_admin()` function. It's not a tag to check whether or not the *user* is an admin, it's a template tag to check if you're on an admin page. From the [Codex](http://codex.wordpress.org/Function_Reference/is_admin): > > This Conditional Tag checks if the Dashboard or the administration pa...
81,522
<p>I have a Wordpress blog and am trying to implement the <a href="https://github.com/adamdbradley/foresight.js" rel="nofollow">foresight.js</a> image script. In short, I need to target all post images, swap out the <code>src, width, &amp; height</code> attributes with <code>data-src, data-width, &amp; data-height</cod...
[ { "answer_id": 84542, "author": "Sunyatasattva", "author_id": 24240, "author_profile": "https://wordpress.stackexchange.com/users/24240", "pm_score": 3, "selected": false, "text": "<p>The filters you are trying to use run on <strong>image insertion</strong>, so it is not possible to swap...
2013/01/14
[ "https://wordpress.stackexchange.com/questions/81522", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/26011/" ]
I have a Wordpress blog and am trying to implement the [foresight.js](https://github.com/adamdbradley/foresight.js) image script. In short, I need to target all post images, swap out the `src, width, & height` attributes with `data-src, data-width, & data-height` attributes. I then need to duplicate the image line and ...
The filters you are trying to use run on **image insertion**, so it is not possible to swap all the images already present in your posts using these filters. It should work, however, if you intend to change to `img` tags *from now on*. The filter [`the_content`](http://codex.wordpress.org/Plugin_API/Filter_Reference/t...
81,523
<p>After creating a custom post type I made a custom template file for the post (<code>single-customposttypename.php</code>). So the URL structure would be: <code>example.com/page/postname</code>, and <code>postname</code> would be the post that renders <code>single-custompostype.php</code> (this works fine). </p> <p...
[ { "answer_id": 81527, "author": "diggy", "author_id": 25765, "author_profile": "https://wordpress.stackexchange.com/users/25765", "pm_score": 2, "selected": false, "text": "<p>From the <a href=\"http://codex.wordpress.org/Post_Type_Templates\" rel=\"nofollow\">codex</a>: If the custom po...
2013/01/14
[ "https://wordpress.stackexchange.com/questions/81523", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/26013/" ]
After creating a custom post type I made a custom template file for the post (`single-customposttypename.php`). So the URL structure would be: `example.com/page/postname`, and `postname` would be the post that renders `single-custompostype.php` (this works fine). But what I'm trying to get is `example.com/PAGE` to lo...
There are two different ways to implement what you want to do, and both are perfectly valid, depending on your needs: 1. Post-type archive index page 2. Custom page template Post-type archive index page ---------------------------- This implementation uses [the WordPress template hierarchy](http://codex.wordpress.or...
81,532
<p>I want to output an image caption in this kind of format:</p> <pre><code>&lt;img class="alignleft size-medium wp-image-316" alt="Image Title" data-caption="Here lies the image caption" src="http://example.com/wp-content/uploads/image-400x266.jpg" width="400" height="266"&gt; </code></pre> <p>I got <a href="http://...
[ { "answer_id": 81535, "author": "M-R", "author_id": 17061, "author_profile": "https://wordpress.stackexchange.com/users/17061", "pm_score": 1, "selected": false, "text": "<p>You can use string replacement function to add the data-caption attribute.</p>\n\n<pre><code>function my_custom_im...
2013/01/14
[ "https://wordpress.stackexchange.com/questions/81532", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/5581/" ]
I want to output an image caption in this kind of format: ``` <img class="alignleft size-medium wp-image-316" alt="Image Title" data-caption="Here lies the image caption" src="http://example.com/wp-content/uploads/image-400x266.jpg" width="400" height="266"> ``` I got [the basic caption code from WP Core](http://cor...
Basically the `img_caption_shortcode` filter allows you to completely replace the default image caption. If you want to do that, you'll need to ask WP to pass all the argument of the filter to your callback function. ``` <?php add_filter('img_caption_shortcode', 'wpse81532_caption', 10, 3 /* three args */); ``` Then...
81,555
<p>I'm trying to hook into WordPress publish. The code below is what I'm using, but it doesn't appear to be running. I have it in a plugin file that I deactivate/reactivate each time I make changes (not sure if that's necessary to do that though). Post type is "auction".</p> <pre><code>add_action( 'publish_auction'...
[ { "answer_id": 81553, "author": "Muhammad Furqan", "author_id": 25586, "author_profile": "https://wordpress.stackexchange.com/users/25586", "pm_score": 0, "selected": false, "text": "<p>I don't think there is any way to use \"/\" in slug. I have Another solution for you. Create custom po...
2013/01/14
[ "https://wordpress.stackexchange.com/questions/81555", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/20603/" ]
I'm trying to hook into WordPress publish. The code below is what I'm using, but it doesn't appear to be running. I have it in a plugin file that I deactivate/reactivate each time I make changes (not sure if that's necessary to do that though). Post type is "auction". ``` add_action( 'publish_auction', 'bvf_set_ceilin...
Make sure to flush rewrite rules after changing the permalink structure, this can be done by visiting the `Settings > Permalinks` page in admin.
81,556
<p>I'm trying to display the total number of comments for a users posts limited to a comment meta. I've tried using both <code>get_comments()</code> and <code>WP_Comment_Query()</code> but I get the same result of "1" for the comment count when it should be "3". Now in this example I can remove <code>'Count' =&gt; true...
[ { "answer_id": 81553, "author": "Muhammad Furqan", "author_id": 25586, "author_profile": "https://wordpress.stackexchange.com/users/25586", "pm_score": 0, "selected": false, "text": "<p>I don't think there is any way to use \"/\" in slug. I have Another solution for you. Create custom po...
2013/01/14
[ "https://wordpress.stackexchange.com/questions/81556", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/12700/" ]
I'm trying to display the total number of comments for a users posts limited to a comment meta. I've tried using both `get_comments()` and `WP_Comment_Query()` but I get the same result of "1" for the comment count when it should be "3". Now in this example I can remove `'Count' => true` and just loop through the comme...
Make sure to flush rewrite rules after changing the permalink structure, this can be done by visiting the `Settings > Permalinks` page in admin.
81,566
<p>I'm trying to practice with setting up a front-end post submission form. And I'm getting this error: </p> <pre><code>Warning: Cannot modify header information - headers already sent by (output started at /home/sadlight/public_html/members/wp-content/themes/default-child/announcement-submit.php:1) in /home/sadlight...
[ { "answer_id": 81567, "author": "Otto", "author_id": 2232, "author_profile": "https://wordpress.stackexchange.com/users/2232", "pm_score": 2, "selected": false, "text": "<blockquote>\n <p>headers already sent by (output started at\n /home/sadlight/public_html/members/wp-content/themes/...
2013/01/14
[ "https://wordpress.stackexchange.com/questions/81566", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/23126/" ]
I'm trying to practice with setting up a front-end post submission form. And I'm getting this error: ``` Warning: Cannot modify header information - headers already sent by (output started at /home/sadlight/public_html/members/wp-content/themes/default-child/announcement-submit.php:1) in /home/sadlight/public_html/me...
As Otto pointed out, you're sending data to the browser before calling `wp_redirect()`. * `get_header()` will output the page's HTML `<head>` * You're printing the entire form to the page before processing it. To fix the "headers already sent" issue, you need to move all of your form processing from the bottom of th...
81,576
<p>I can successfully query post results using query posts like so... </p> <pre><code>&lt;?php // The Query query_posts("gdsr_sort=rating"); // The Loop while ( have_posts() ) : the_post(); ?&gt; &lt;?php get_template_part( 'content', get_post_format() ); ?&gt; &lt;?php endwhile; // Reset Query wp_reset_query(); ...
[ { "answer_id": 81567, "author": "Otto", "author_id": 2232, "author_profile": "https://wordpress.stackexchange.com/users/2232", "pm_score": 2, "selected": false, "text": "<blockquote>\n <p>headers already sent by (output started at\n /home/sadlight/public_html/members/wp-content/themes/...
2013/01/14
[ "https://wordpress.stackexchange.com/questions/81576", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25423/" ]
I can successfully query post results using query posts like so... ``` <?php // The Query query_posts("gdsr_sort=rating"); // The Loop while ( have_posts() ) : the_post(); ?> <?php get_template_part( 'content', get_post_format() ); ?> <?php endwhile; // Reset Query wp_reset_query(); ?> ``` I was wondering if i...
As Otto pointed out, you're sending data to the browser before calling `wp_redirect()`. * `get_header()` will output the page's HTML `<head>` * You're printing the entire form to the page before processing it. To fix the "headers already sent" issue, you need to move all of your form processing from the bottom of th...
81,577
<p>I want to be able to echo the URL of the featured image of a post and after looking some on the web I found the following which works fine when I put it in a loop in my front page template. </p> <pre><code>&lt;?php $thumbSmall = wp_get_attachment_image_src( get_post_thumbnail_id($post-&gt;ID), 'small' ); $urlSmall ...
[ { "answer_id": 81583, "author": "diggy", "author_id": 25765, "author_profile": "https://wordpress.stackexchange.com/users/25765", "pm_score": 4, "selected": true, "text": "<p>You can turn your snippet into a function that returns the post thumbnail URL of a post:</p>\n\n<pre><code>functi...
2013/01/14
[ "https://wordpress.stackexchange.com/questions/81577", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/26027/" ]
I want to be able to echo the URL of the featured image of a post and after looking some on the web I found the following which works fine when I put it in a loop in my front page template. ``` <?php $thumbSmall = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'small' ); $urlSmall = $thumbSmall['0']; ...
You can turn your snippet into a function that returns the post thumbnail URL of a post: ``` function wpse81577_get_small_thumb_url( $post_id ) { $thumbSmall = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'small' ); return $thumbSmall['0']; } ``` Usage, supplying the ID of a post: ``` <?p...
81,580
<p>Is it possible to get a specific Gallery ID inserted to a post in wordpress 3.5? I want to load gallery from post using Ajax. I use shortcode <code>[gallery]</code> to do it. But when I use it this way: </p> <pre><code>echo do_shortcode('[gallery id="'.$_POST['postid'].'"]'); </code></pre> <p>I get all images atta...
[ { "answer_id": 81609, "author": "Knut Sparhell", "author_id": 26032, "author_profile": "https://wordpress.stackexchange.com/users/26032", "pm_score": 0, "selected": false, "text": "<p>The plain, old [gallery] should still work here.</p>\n" }, { "answer_id": 81643, "author": "...
2013/01/15
[ "https://wordpress.stackexchange.com/questions/81580", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/22533/" ]
Is it possible to get a specific Gallery ID inserted to a post in wordpress 3.5? I want to load gallery from post using Ajax. I use shortcode `[gallery]` to do it. But when I use it this way: ``` echo do_shortcode('[gallery id="'.$_POST['postid'].'"]'); ``` I get all images attached to the post with $\_POST['postid...
In single.php i put this code, from this link (thank you Wyck) <https://stackoverflow.com/questions/14277794/wordpress-3-5-own-gallery-with-included-images-doesnt-work> ``` preg_match('/\[gallery.*ids=.(.*).\]/', $post_content, $ids); $array_id = explode(",", $ids[1]); print_r($array_id); ``` Now I can use gallery ...
81,597
<p>I'm building a <code>&lt;select&gt;</code> dropdown to display a list of terms for a custom hierarchical taxonomy. How do I know the depth of each term? I'd like to add some indentation for child-terms (the more deeply they're nested, the more indentation there should be).</p> <p>However I'm not able to retrieve th...
[ { "answer_id": 81622, "author": "Mike Madern", "author_id": 24806, "author_profile": "https://wordpress.stackexchange.com/users/24806", "pm_score": 3, "selected": true, "text": "<p>You can use <a href=\"http://codex.wordpress.org/Function_Reference/wp_dropdown_categories\" rel=\"nofollow...
2013/01/15
[ "https://wordpress.stackexchange.com/questions/81597", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/8421/" ]
I'm building a `<select>` dropdown to display a list of terms for a custom hierarchical taxonomy. How do I know the depth of each term? I'd like to add some indentation for child-terms (the more deeply they're nested, the more indentation there should be). However I'm not able to retrieve the depth level from `get_ter...
You can use [wp\_dropdown\_categories()](http://codex.wordpress.org/Function_Reference/wp_dropdown_categories): > > Display or retrieve the HTML dropdown list of categories. > > > ``` $args = array( 'show_count' => 1, 'hierarchical' => 1, 'taxonomy' => 'my_taxonomy', ); wp_dropdown_categories( ...
81,626
<p>Is there any way to filter the categories of a post? I am using <code>wp_get_post_categories( $post -&gt; ID );</code> i want to filter this listing i.e. <code>if(post_name or post_id == "some id or some name") {it should not be displayed}</code></p>
[ { "answer_id": 81622, "author": "Mike Madern", "author_id": 24806, "author_profile": "https://wordpress.stackexchange.com/users/24806", "pm_score": 3, "selected": true, "text": "<p>You can use <a href=\"http://codex.wordpress.org/Function_Reference/wp_dropdown_categories\" rel=\"nofollow...
2013/01/15
[ "https://wordpress.stackexchange.com/questions/81626", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25844/" ]
Is there any way to filter the categories of a post? I am using `wp_get_post_categories( $post -> ID );` i want to filter this listing i.e. `if(post_name or post_id == "some id or some name") {it should not be displayed}`
You can use [wp\_dropdown\_categories()](http://codex.wordpress.org/Function_Reference/wp_dropdown_categories): > > Display or retrieve the HTML dropdown list of categories. > > > ``` $args = array( 'show_count' => 1, 'hierarchical' => 1, 'taxonomy' => 'my_taxonomy', ); wp_dropdown_categories( ...
81,633
<p>When Im in wp-admin and editing a page and whant to make underline, bold and italic it dont appear on the site. I understand therese something i have to define in the css or thru wp-admin ?</p> <p>NOTE: I want the user to easly edit and i know how to do it thru css. But what I want is to edit thru the edit-page.</p...
[ { "answer_id": 81622, "author": "Mike Madern", "author_id": 24806, "author_profile": "https://wordpress.stackexchange.com/users/24806", "pm_score": 3, "selected": true, "text": "<p>You can use <a href=\"http://codex.wordpress.org/Function_Reference/wp_dropdown_categories\" rel=\"nofollow...
2013/01/15
[ "https://wordpress.stackexchange.com/questions/81633", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/21256/" ]
When Im in wp-admin and editing a page and whant to make underline, bold and italic it dont appear on the site. I understand therese something i have to define in the css or thru wp-admin ? NOTE: I want the user to easly edit and i know how to do it thru css. But what I want is to edit thru the edit-page.
You can use [wp\_dropdown\_categories()](http://codex.wordpress.org/Function_Reference/wp_dropdown_categories): > > Display or retrieve the HTML dropdown list of categories. > > > ``` $args = array( 'show_count' => 1, 'hierarchical' => 1, 'taxonomy' => 'my_taxonomy', ); wp_dropdown_categories( ...
81,645
<p>I need to get all sub-posts of a specific (root) parent id.</p> <pre><code>get_posts( array( 'numberposts' =&gt; -1, 'post_status' =&gt; 'publish', 'post_type' =&gt; 'microsite', 'post_parent' =&gt; $root_parent_id, 'suppress_filters' =&gt; false ) ); </code></pre> <p>WP-Codex: <a href="http://codex.wordpress.org/...
[ { "answer_id": 81648, "author": "Tom J Nowell", "author_id": 736, "author_profile": "https://wordpress.stackexchange.com/users/736", "pm_score": 5, "selected": true, "text": "<p>You will need to loop over those posts and then do more queries for each post, repeating until you find no pos...
2013/01/15
[ "https://wordpress.stackexchange.com/questions/81645", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/10590/" ]
I need to get all sub-posts of a specific (root) parent id. ``` get_posts( array( 'numberposts' => -1, 'post_status' => 'publish', 'post_type' => 'microsite', 'post_parent' => $root_parent_id, 'suppress_filters' => false ) ); ``` WP-Codex: [get\_post()](http://codex.wordpress.org/Function_Reference/get_posts) functi...
You will need to loop over those posts and then do more queries for each post, repeating until you find no posts in a query. e.g. ``` function get_posts_children($parent_id){ $children = array(); // grab the posts children $posts = get_posts( array( 'numberposts' => -1, 'post_status' => 'publish', 'post_t...
81,653
<p>I'd like to customize the log-in page for my WordPress theme and although I can play around with the CSS, I would love to re-position the "Lost your password?" and "← Back to Site" links to be inside of the foreground box, rather than below it / or, in other words...so these links are placed inside of the form-field...
[ { "answer_id": 81648, "author": "Tom J Nowell", "author_id": 736, "author_profile": "https://wordpress.stackexchange.com/users/736", "pm_score": 5, "selected": true, "text": "<p>You will need to loop over those posts and then do more queries for each post, repeating until you find no pos...
2013/01/15
[ "https://wordpress.stackexchange.com/questions/81653", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/16795/" ]
I'd like to customize the log-in page for my WordPress theme and although I can play around with the CSS, I would love to re-position the "Lost your password?" and "← Back to Site" links to be inside of the foreground box, rather than below it / or, in other words...so these links are placed inside of the form-field. ...
You will need to loop over those posts and then do more queries for each post, repeating until you find no posts in a query. e.g. ``` function get_posts_children($parent_id){ $children = array(); // grab the posts children $posts = get_posts( array( 'numberposts' => -1, 'post_status' => 'publish', 'post_t...
81,659
<p>Is there a simple way to temporarily stop a user role logging in with wordpress?</p> <p>For example, if I have a user role called <strong>media</strong>, how can I block them from logging in?</p> <p>I would like a custom message to appear on the website, for example like 'Site undergoing maintenance'</p> <p>So it lo...
[ { "answer_id": 81661, "author": "diggy", "author_id": 25765, "author_profile": "https://wordpress.stackexchange.com/users/25765", "pm_score": 2, "selected": false, "text": "<p>Add in a check for a capability that admins and editors share:</p>\n\n<pre><code>add_action( 'get_header', 'wpse...
2013/01/15
[ "https://wordpress.stackexchange.com/questions/81659", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/11327/" ]
Is there a simple way to temporarily stop a user role logging in with wordpress? For example, if I have a user role called **media**, how can I block them from logging in? I would like a custom message to appear on the website, for example like 'Site undergoing maintenance' So it looks like this: ![http://i.imgur.c...
With a some digging and learning, I managed to combine various help and create these 2 functions... ``` // MAINTAINANCE MODE function site_maintenance() { if ( current_user_can('media') || current_user_can('genpo') ) { $logout_url = wp_login_url().'?mode=maintainance'; wp_logout(); wp_redirec...
81,672
<p>I am adding a list of suggested plugins to my theme using TGM Plugin Activation - <a href="https://github.com/thomasgriffin/TGM-Plugin-Activation/" rel="nofollow">https://github.com/thomasgriffin/TGM-Plugin-Activation/</a></p> <p>However, when I run theme check, about 40 or so recommendations popped up because the ...
[ { "answer_id": 81681, "author": "kaiser", "author_id": 385, "author_profile": "https://wordpress.stackexchange.com/users/385", "pm_score": 3, "selected": true, "text": "<p>The translation strings not only get parsed during rendering (output on screen/in browser), but also by the GNU gett...
2013/01/15
[ "https://wordpress.stackexchange.com/questions/81672", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/24181/" ]
I am adding a list of suggested plugins to my theme using TGM Plugin Activation - <https://github.com/thomasgriffin/TGM-Plugin-Activation/> However, when I run theme check, about 40 or so recommendations popped up because the plugin uses variables in translatable functions. I was able to remove about half of the probl...
The translation strings not only get parsed during rendering (output on screen/in browser), but also by the GNU gettext parser. This one is *not* a PHP parser, so it can't fetch variables. This is the only part of a Theme or a Plugin, where you need to repeat yourself and **add the plain string** to *every* translation...
81,677
<p>Is it possible to change the image size of the thumbnails in the new media uploader?</p> <p>For example images are currently displayed using the "thumbnail" image crop size and I would like them to be the "medium" image crop size.</p>
[ { "answer_id": 86999, "author": "brasofilo", "author_id": 12615, "author_profile": "https://wordpress.stackexchange.com/users/12615", "pm_score": 2, "selected": true, "text": "<p>Supposing that I'm <a href=\"http://msmvps.com/blogs/jon_skeet/archive/2010/08/29/writing-the-perfect-questio...
2013/01/15
[ "https://wordpress.stackexchange.com/questions/81677", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/1057/" ]
Is it possible to change the image size of the thumbnails in the new media uploader? For example images are currently displayed using the "thumbnail" image crop size and I would like them to be the "medium" image crop size.
Supposing that I'm [interpreting your Question correctly](http://msmvps.com/blogs/jon_skeet/archive/2010/08/29/writing-the-perfect-question.aspx)... The thumbnails displayed in the new Media Uploader are already the `medium` sized ones, being constrained on the fly. > > [![media uploader inspector](https://i.stack.i...
81,683
<p>I don't know what to do here but pagination is driving me crazy! As you can see, "Older" points to blog/page/2 but when clicked, the site stays on blog/.</p> <p>I'm using wp-pagenavi for pagination.</p> <p>The site url is <a href="http://www.grassroottech.com/blog" rel="nofollow">http://www.grassroottech.com/blog<...
[ { "answer_id": 86999, "author": "brasofilo", "author_id": 12615, "author_profile": "https://wordpress.stackexchange.com/users/12615", "pm_score": 2, "selected": true, "text": "<p>Supposing that I'm <a href=\"http://msmvps.com/blogs/jon_skeet/archive/2010/08/29/writing-the-perfect-questio...
2013/01/15
[ "https://wordpress.stackexchange.com/questions/81683", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/26065/" ]
I don't know what to do here but pagination is driving me crazy! As you can see, "Older" points to blog/page/2 but when clicked, the site stays on blog/. I'm using wp-pagenavi for pagination. The site url is <http://www.grassroottech.com/blog> Sorry, here is the blog template page: (embedding not working - <http://p...
Supposing that I'm [interpreting your Question correctly](http://msmvps.com/blogs/jon_skeet/archive/2010/08/29/writing-the-perfect-question.aspx)... The thumbnails displayed in the new Media Uploader are already the `medium` sized ones, being constrained on the fly. > > [![media uploader inspector](https://i.stack.i...
81,693
<p>Instead of calling a script from a file, I put a number of my javascripts in a template file called codes.php.</p> <p>I then call codes.php in the footer by pasting <code>&lt;?php include (TEMPLATEPATH . '/codes.php'); ?&gt;</code> into footer.php</p> <p>Should I continue with this method, or should I be saving e...
[ { "answer_id": 81701, "author": "Muhammad Furqan", "author_id": 25586, "author_profile": "https://wordpress.stackexchange.com/users/25586", "pm_score": 1, "selected": false, "text": "<p>I am unable to understand your Question but WordPress provide a good way to use java script files <a h...
2013/01/15
[ "https://wordpress.stackexchange.com/questions/81693", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/5205/" ]
Instead of calling a script from a file, I put a number of my javascripts in a template file called codes.php. I then call codes.php in the footer by pasting `<?php include (TEMPLATEPATH . '/codes.php'); ?>` into footer.php Should I continue with this method, or should I be saving each script in its own file, upload ...
If I interpret the question correctly you: * Don't have any .js javascript files * Output any javascript you have from an .php file (presumably code) * Include this javascript on the bottom of the page by including the .php file. So you are actually doing: * **Correct** + Combining all the javascript in one file +...
81,695
<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://wordpress.stackexchange.com/questions/80454/how-to-know-which-one-is-the-main-query">How to know which one is the main query?</a> </p> </blockquote> <p>I'm curious to know what is the so called "main query"?</p> <p>What I have is two que...
[ { "answer_id": 81698, "author": "fuxia", "author_id": 73, "author_profile": "https://wordpress.stackexchange.com/users/73", "pm_score": 2, "selected": false, "text": "<p>The main query is the one triggered automatically when WordPress has determined what to show for the request URI.</p>\...
2013/01/15
[ "https://wordpress.stackexchange.com/questions/81695", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/26064/" ]
> > **Possible Duplicate:** > > [How to know which one is the main query?](https://wordpress.stackexchange.com/questions/80454/how-to-know-which-one-is-the-main-query) > > > I'm curious to know what is the so called "main query"? What I have is two queries on front page. ``` if (have_posts()) : while (have_p...
The filter has a bug in it, namely when it calls `is_main_query`, it's not checking if the passed `$query` is the main query, it's checking if the *currently active query* is the main query, which will always be true. So instead try this: ```php add_action( 'pre_get_posts', 'modify_frontpage_main_query' ); function m...
81,722
<p>I have encountered some problems after I have redirected my site, which is in a sub directory in my server, to a new domain. I have kept the same server.</p> <p>The origin URL of my wp site <code>http://www.example.com/mywpblog</code>, has been redirected to another new domain <code>http://www.example.com</code>.<...
[ { "answer_id": 81744, "author": "akTed", "author_id": 25472, "author_profile": "https://wordpress.stackexchange.com/users/25472", "pm_score": -1, "selected": false, "text": "<p>Unfortunately you can't just move a WordPress install to a new domain (or even a different directory) without ...
2013/01/15
[ "https://wordpress.stackexchange.com/questions/81722", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/26033/" ]
I have encountered some problems after I have redirected my site, which is in a sub directory in my server, to a new domain. I have kept the same server. The origin URL of my wp site `http://www.example.com/mywpblog`, has been redirected to another new domain `http://www.example.com`. Please help me solve the followi...
There is a search and replace plugin I have used that works pretty good. <http://wordpress.org/extend/plugins/search-and-replace/> In the future I would not hard code any links in if you can help it as well. Use dynamic linking like: ``` $url = site_url('/secrets/'); echo $url; ``` or: ``` img src="<?php echo get...
81,733
<p>I'm currently working with custom comment meta, and I have some custom additional field such as rating etc, when user write a comment ( not comment reply ) I want to show the rating field, but when it's on reply comment state I want to remove this field.</p> <p>Is there a build in conditional function to check whet...
[ { "answer_id": 81735, "author": "diggy", "author_id": 25765, "author_profile": "https://wordpress.stackexchange.com/users/25765", "pm_score": 2, "selected": false, "text": "<p>Check for the <code>comment_parent</code>:</p>\n\n<pre><code>if( '0' != $comment-&gt;comment_parent ){\n // t...
2013/01/15
[ "https://wordpress.stackexchange.com/questions/81733", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/10997/" ]
I'm currently working with custom comment meta, and I have some custom additional field such as rating etc, when user write a comment ( not comment reply ) I want to show the rating field, but when it's on reply comment state I want to remove this field. Is there a build in conditional function to check whether it's i...
Check for the `comment_parent`: ``` if( '0' != $comment->comment_parent ){ // this is a reply } ```
81,749
<p>Elliot here from the "Advanced Custom Fields" plugin.</p> <p>I'm working on integrating the new WP 3.5 uploader into the ACF plugin and can't find much documentation about the new uploader at all!</p> <p>Creating an uploader frame is easy, that can be done like this:</p> <pre><code>// Create the media frame. acf....
[ { "answer_id": 81751, "author": "Bronson Quick", "author_id": 26081, "author_profile": "https://wordpress.stackexchange.com/users/26081", "pm_score": 3, "selected": false, "text": "<p>Looks like you've figured it out but seeing I use ACF all the time I figured I could link you to a coupl...
2013/01/16
[ "https://wordpress.stackexchange.com/questions/81749", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25950/" ]
Elliot here from the "Advanced Custom Fields" plugin. I'm working on integrating the new WP 3.5 uploader into the ACF plugin and can't find much documentation about the new uploader at all! Creating an uploader frame is easy, that can be done like this: ``` // Create the media frame. acf.media = wp.media({ title...
Looks like you've figured it out but seeing I use ACF all the time I figured I could link you to a couple of awesome posts about the media uploader in 3.5 as the codex still aren't updated yet. Check out: [Using the WordPress 3.5 Media Uploader within plugins](http://mikejolley.com/2012/12/using-the-new-wordpress-3-5-...
81,755
<p>I have a plugin that uses the <code>wp_editor()</code> function to load an instance of the TinyMCE editor.</p> <p>However, the editor is affected by custom styling to make it look similar to the theme through the <code>add_editor_style()</code> function. While this may be great in giving the user an idea of how the...
[ { "answer_id": 81763, "author": "s_ha_dum", "author_id": 21376, "author_profile": "https://wordpress.stackexchange.com/users/21376", "pm_score": 2, "selected": false, "text": "<p>I believe you want <a href=\"http://codex.wordpress.org/Function_Reference/remove_editor_styles\" rel=\"nofol...
2013/01/16
[ "https://wordpress.stackexchange.com/questions/81755", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/19726/" ]
I have a plugin that uses the `wp_editor()` function to load an instance of the TinyMCE editor. However, the editor is affected by custom styling to make it look similar to the theme through the `add_editor_style()` function. While this may be great in giving the user an idea of how the content may look on the front-e...
While @s\_ha\_dum’s solution works fine on a custom plugin page, it will fail if you use TinyMCE on a post editor page after the first editor instance has been called, because it would either affect all editors or at least the editors later on the same page. TinyMCE parses custom styles into its settings during the fir...
81,764
<p>Hi i'm using the code below to call post from a certain Category under certain post types, But how do i style it so that i can make the first post different from the rest of the post.</p> <pre><code>&lt;?php $queryObject = new Wp_Query( array( 'showposts' =&gt; 4, 'post_type' =&gt; array('pretty-li...
[ { "answer_id": 81766, "author": "Milo", "author_id": 4771, "author_profile": "https://wordpress.stackexchange.com/users/4771", "pm_score": 3, "selected": false, "text": "<p>You could check <code>current_post</code> in the loop:</p>\n\n<pre><code>if($queryObject-&gt;have_posts()) {\n w...
2013/01/16
[ "https://wordpress.stackexchange.com/questions/81764", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/20145/" ]
Hi i'm using the code below to call post from a certain Category under certain post types, But how do i style it so that i can make the first post different from the rest of the post. ``` <?php $queryObject = new Wp_Query( array( 'showposts' => 4, 'post_type' => array('pretty-little-liars', 'revenge',...
You could check `current_post` in the loop: ``` if($queryObject->have_posts()) { while($queryObject->have_posts()) { $queryObject->the_post(); if( 0 == $queryObject->current_post ) { // this is the first post } else { // not the first post } } } ```
81,769
<p>I have installed wordpress in a subdirectory (<code>blog</code>). In the root directory I have installed Magento. Now the file directory is as following:</p> <pre><code>app downloader includes media .... blog/wp-admin </code></pre> <p>My server is <strong>nginx</strong>. When I set the URL in the wordpress <em>Pe...
[ { "answer_id": 81782, "author": "PrivateUser", "author_id": 5074, "author_profile": "https://wordpress.stackexchange.com/users/5074", "pm_score": 2, "selected": false, "text": "<p>Place this code in your <code>functions.php</code> file </p>\n\n<pre><code> add_filter( 'got_rewrite', '__...
2013/01/16
[ "https://wordpress.stackexchange.com/questions/81769", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/26085/" ]
I have installed wordpress in a subdirectory (`blog`). In the root directory I have installed Magento. Now the file directory is as following: ``` app downloader includes media .... blog/wp-admin ``` My server is **nginx**. When I set the URL in the wordpress *Permalink Settings* to: ``` http://www.example.com/blo...
Place this code in your `functions.php` file ``` add_filter( 'got_rewrite', '__return_true', 999 ); ``` Update: ------- [got\_mod\_rewrite()](http://core.trac.wordpress.org/browser/tags/3.5/wp-admin/includes/misc.php#L16) function checks whether the current server is apache or not using [apache\_mod\_loaded()](...
81,770
<p>I am using woo commerce theme for my site. I am trying to display a list of main product category list. I tried this code. But it returns all the main and sub categories.</p> <pre><code>$product_category = wp_get_post_terms( $post-&gt;ID, 'product_cat' ); </code></pre> <p>I need to display just the main product ca...
[ { "answer_id": 81771, "author": "Milo", "author_id": 4771, "author_profile": "https://wordpress.stackexchange.com/users/4771", "pm_score": 1, "selected": false, "text": "<p>Check the parent of each category, top-level terms will have a parent value of 0:</p>\n\n<pre><code>$product_catego...
2013/01/16
[ "https://wordpress.stackexchange.com/questions/81770", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/24957/" ]
I am using woo commerce theme for my site. I am trying to display a list of main product category list. I tried this code. But it returns all the main and sub categories. ``` $product_category = wp_get_post_terms( $post->ID, 'product_cat' ); ``` I need to display just the main product category list. How to do that?
Check the parent of each category, top-level terms will have a parent value of 0: ``` $product_category = wp_get_post_terms( $post->ID, 'product_cat' ); foreach( $product_category as $cat ): if( 0 == $cat->parent ) echo $cat->name; endforeach; ```
81,772
<p>How can I disallow contributors on my site from seeing what other posts are published on the site, and only see their own?</p>
[ { "answer_id": 81781, "author": "PrivateUser", "author_id": 5074, "author_profile": "https://wordpress.stackexchange.com/users/5074", "pm_score": 3, "selected": true, "text": "<p>I hope you are talking about wp-admin section. If yes just place this code in your <code>functions.php</code>...
2013/01/16
[ "https://wordpress.stackexchange.com/questions/81772", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/5844/" ]
How can I disallow contributors on my site from seeing what other posts are published on the site, and only see their own?
I hope you are talking about wp-admin section. If yes just place this code in your `functions.php` file ``` add_action( 'load-edit.php', 'posts_for_current_contributor' ); function posts_for_current_contributor() { global $user_ID; if ( current_user_can( 'contributor' ) ) { if ( ! isset( $_GET['author'...
81,773
<p>this is my first time to try this "Defer Parsing" thing, and I don't really have an idea how to do it.</p> <p><img src="https://i.stack.imgur.com/4fJnH.jpg" alt="enter image description here"></p> <p>Using PageSpeed tool, I found out that one of the reason why my page is loading too slow (currently 92/100) are the...
[ { "answer_id": 81775, "author": "fischi", "author_id": 15680, "author_profile": "https://wordpress.stackexchange.com/users/15680", "pm_score": 2, "selected": false, "text": "<p>At the first glance, you sure have a lot of Javascript included in your Website. You can take a few steps towar...
2013/01/16
[ "https://wordpress.stackexchange.com/questions/81773", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/9583/" ]
this is my first time to try this "Defer Parsing" thing, and I don't really have an idea how to do it. ![enter image description here](https://i.stack.imgur.com/4fJnH.jpg) Using PageSpeed tool, I found out that one of the reason why my page is loading too slow (currently 92/100) are the scripts. And the PageSpeed sug...
At the first glance, you sure have a lot of Javascript included in your Website. You can take a few steps towards reducing/speeding up this section. Before I start, please let me remind you that the PageSpeed by Google is not an actual tool to keasure how fast a website loads, it is more a tool to see how you can set ...
81,785
<p>my single posts is getting 31 query from mysql. I checked all queries. I saw this query.</p> <p>I am using <strong>last posts</strong> and <strong>categories</strong> widget. I think there query is unnecessary.How to remove theme</p> <pre>Query: SELECT option_value FROM xy_options WHERE option_name = 'widget_pages...
[ { "answer_id": 81799, "author": "fischi", "author_id": 15680, "author_profile": "https://wordpress.stackexchange.com/users/15680", "pm_score": 0, "selected": false, "text": "<p>From a glance at your Code, your <code>sidebar.php</code> is quite extensive and variable.</p>\n\n<p>The Option...
2013/01/16
[ "https://wordpress.stackexchange.com/questions/81785", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25086/" ]
my single posts is getting 31 query from mysql. I checked all queries. I saw this query. I am using **last posts** and **categories** widget. I think there query is unnecessary.How to remove theme ``` Query: SELECT option_value FROM xy_options WHERE option_name = 'widget_pages' LIMIT 1 Query: SELECT option_value FROM...
Best I can tell is that those default widgets get options from the database as their classes are constructed, so there's no way to prevent the DB queries without disabling those widgets entirely. Depending on your needs, you may want that slight performance bump and do not need the widgets, in which case you can use th...
81,791
<p>We have a bespoke Wordpress plugin, which adds a meta box to the edit post page. The plugin accesses data from a semi-private HTTP REST API.</p> <p>The connection is authenticated (DIGEST) and accessed regularly - every person writing a post will interact with it several times (usually in tight bursts) and there ar...
[ { "answer_id": 81799, "author": "fischi", "author_id": 15680, "author_profile": "https://wordpress.stackexchange.com/users/15680", "pm_score": 0, "selected": false, "text": "<p>From a glance at your Code, your <code>sidebar.php</code> is quite extensive and variable.</p>\n\n<p>The Option...
2013/01/16
[ "https://wordpress.stackexchange.com/questions/81791", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/22458/" ]
We have a bespoke Wordpress plugin, which adds a meta box to the edit post page. The plugin accesses data from a semi-private HTTP REST API. The connection is authenticated (DIGEST) and accessed regularly - every person writing a post will interact with it several times (usually in tight bursts) and there are > 100 su...
Best I can tell is that those default widgets get options from the database as their classes are constructed, so there's no way to prevent the DB queries without disabling those widgets entirely. Depending on your needs, you may want that slight performance bump and do not need the widgets, in which case you can use th...
81,797
<p>I use custom menus and I’d like to get the menu item slugs. Is that possible?</p> <pre><code>// Get the nav menu based on $menu_name (same as 'theme_location' or 'menu' arg to wp_nav_menu) // This code based on wp_nav_menu's code to get Menu ID from menu slug $menu_name = 'main-menu'; if ( ( $locations = get_nav_...
[ { "answer_id": 81814, "author": "user1706680", "author_id": 21110, "author_profile": "https://wordpress.stackexchange.com/users/21110", "pm_score": -1, "selected": false, "text": "<p>It’s possible to grab the slug with <code>$menu_item-&gt;post_name;</code>.</p>\n" }, { "answer_i...
2013/01/16
[ "https://wordpress.stackexchange.com/questions/81797", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/21110/" ]
I use custom menus and I’d like to get the menu item slugs. Is that possible? ``` // Get the nav menu based on $menu_name (same as 'theme_location' or 'menu' arg to wp_nav_menu) // This code based on wp_nav_menu's code to get Menu ID from menu slug $menu_name = 'main-menu'; if ( ( $locations = get_nav_menu_locations...
Well you've Post ID with you. So you can use this custom function to retrieve slug of any post. ``` function get_the_slug( $id=null ){ if( empty($id) ): global $post; if( empty($post) ) return ''; // No global $post var available. $id = $post->ID; endif; $slug = basenam...
81,803
<p>The setting <code>Settings -&gt; Reading -&gt; Posts Page</code> is set to my 'News' page, and the loop for the <code>home.php</code> template is populated with posts... great.</p> <p>However I want to also be able to create another loop (even with <code>WP_Query</code> if needed) of which contains the actual page ...
[ { "answer_id": 81804, "author": "Mike Madern", "author_id": 24806, "author_profile": "https://wordpress.stackexchange.com/users/24806", "pm_score": 1, "selected": false, "text": "<p>You can get the selected page for posts by the following code:</p>\n\n<pre><code>$page_for_posts = get_opt...
2013/01/16
[ "https://wordpress.stackexchange.com/questions/81803", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/29/" ]
The setting `Settings -> Reading -> Posts Page` is set to my 'News' page, and the loop for the `home.php` template is populated with posts... great. However I want to also be able to create another loop (even with `WP_Query` if needed) of which contains the actual page of which I've specified my `Posts Page` to be. W...
You can get the selected page for posts by the following code: ``` $page_for_posts = get_option( 'page_for_posts' ); ``` Then, get the requested post by: ``` $post = get_post( $page_for_posts ); ``` And, get the data you need: ``` echo apply_filters( 'the_title', $post->post_title ); echo apply_filters( 'the_con...
81,821
<p>How can I have to set tax_query to get results like 'category__in' => array()?</p> <p>Specifically, I would like to show all the posts that have a term from the city taxonomy with one of these id's: <code>$cities = array(23,34,45,56);</code></p> <p>This is the code I currently use.</p> <pre><code>$paged = (get_qu...
[ { "answer_id": 81804, "author": "Mike Madern", "author_id": 24806, "author_profile": "https://wordpress.stackexchange.com/users/24806", "pm_score": 1, "selected": false, "text": "<p>You can get the selected page for posts by the following code:</p>\n\n<pre><code>$page_for_posts = get_opt...
2013/01/16
[ "https://wordpress.stackexchange.com/questions/81821", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/26030/" ]
How can I have to set tax\_query to get results like 'category\_\_in' => array()? Specifically, I would like to show all the posts that have a term from the city taxonomy with one of these id's: `$cities = array(23,34,45,56);` This is the code I currently use. ``` $paged = (get_query_var('paged')) ? get_query_var('p...
You can get the selected page for posts by the following code: ``` $page_for_posts = get_option( 'page_for_posts' ); ``` Then, get the requested post by: ``` $post = get_post( $page_for_posts ); ``` And, get the data you need: ``` echo apply_filters( 'the_title', $post->post_title ); echo apply_filters( 'the_con...
81,842
<p>How can I query all the posts from either the custom post type ('videos') or with a post category ('video') in a loop?</p> <p>I've managed to create a query that combines the posts from a custom post type and the normal posts using the code below, but am struggling with achieving the same with a custom post type an...
[ { "answer_id": 81849, "author": "Derk-Jan", "author_id": 9948, "author_profile": "https://wordpress.stackexchange.com/users/9948", "pm_score": 3, "selected": true, "text": "<p><strong>Must have both</strong></p>\n\n<p>The following arguments array searches for the post-type-slug <code>vi...
2013/01/16
[ "https://wordpress.stackexchange.com/questions/81842", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25846/" ]
How can I query all the posts from either the custom post type ('videos') or with a post category ('video') in a loop? I've managed to create a query that combines the posts from a custom post type and the normal posts using the code below, but am struggling with achieving the same with a custom post type and a post c...
**Must have both** The following arguments array searches for the post-type-slug `videos` and category-slug `video`. It doesn't use pagination by setting `posts_per_page` to -1 and only returns published posts. ``` $args = array( 'post_type' => 'videos', 'category_name' => 'video', 'posts_per_page' => ...
81,850
<p>I'm trying to add a rewrite rule to Wordpress. I want to rewrite: "http://www.domain.com/plm_check/var_a/var_b/var_c/" to actually use a file from "http://www.domain.com/wp-content/plugins/plm/webservices/plm_check.php?var_a=...&amp;var_b=...&amp;var_c=..."</p> <p>I've registered it like this:</p> <pre><code>/* R...
[ { "answer_id": 81862, "author": "Mark Kaplun", "author_id": 23970, "author_profile": "https://wordpress.stackexchange.com/users/23970", "pm_score": 0, "selected": false, "text": "<p>In your case <code>add_rewrite_rul()</code> will call <code>add_external_rule()</code> which collects rule...
2013/01/16
[ "https://wordpress.stackexchange.com/questions/81850", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/26107/" ]
I'm trying to add a rewrite rule to Wordpress. I want to rewrite: "http://www.domain.com/plm\_check/var\_a/var\_b/var\_c/" to actually use a file from "http://www.domain.com/wp-content/plugins/plm/webservices/plm\_check.php?var\_a=...&var\_b=...&var\_c=..." I've registered it like this: ``` /* Register rewrites for w...
Here's a quick (hopefully error-free!) example of adding an internal rewrite and loading a plugin file to process those requests. This will give you access to the WordPress environment so you can [use the database](http://codex.wordpress.org/Class_Reference/wpdb), etc.. The general steps are: 1. add your rewrite and ...
81,864
<p>I tried all solutions of the topics here but I haven't been able to find a solution. I made a Plugin for a Shortcode. My problem is that the plugin code get always loaded above the content. I already found out that it comes from the use of <code>echo</code>. Instead I should use <code>return</code>. But as soon I re...
[ { "answer_id": 81866, "author": "diggy", "author_id": 25765, "author_profile": "https://wordpress.stackexchange.com/users/25765", "pm_score": 3, "selected": true, "text": "<p>First, declare your variable:</p>\n\n<pre><code>$return = '';\n</code></pre>\n\n<p>Then, throughout the code, con...
2013/01/16
[ "https://wordpress.stackexchange.com/questions/81864", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/10436/" ]
I tried all solutions of the topics here but I haven't been able to find a solution. I made a Plugin for a Shortcode. My problem is that the plugin code get always loaded above the content. I already found out that it comes from the use of `echo`. Instead I should use `return`. But as soon I replace the `echo` the plug...
First, declare your variable: ``` $return = ''; ``` Then, throughout the code, concatenate items: ``` $return .= '<div class="sp shadow"><img src="..."></div>'; $return .= '<h3>Videos</h3>'; ``` And finally, return the result: ``` return $return; ```
81,879
<p>Reading through the <a href="http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters" rel="nofollow noreferrer">order &amp; orderby documentation</a>, it's not clear to me whether there is any support to order based on multiple <code>meta_key</code> values.</p> <p>Obviously, using <code>met...
[ { "answer_id": 184676, "author": "forsvunnet", "author_id": 45792, "author_profile": "https://wordpress.stackexchange.com/users/45792", "pm_score": 0, "selected": false, "text": "<p>If you look at the get_posts method of WP_Query it's easy to debug the sql by outputting the variable pass...
2013/01/16
[ "https://wordpress.stackexchange.com/questions/81879", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/15299/" ]
Reading through the [order & orderby documentation](http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters), it's not clear to me whether there is any support to order based on multiple `meta_key` values. Obviously, using `meta_query` I can return posts based on multiple key-value pairs, but ...
You might want to check out the query improvements in WP 4.2 for ‘orderby’ and ‘meta\_query’. Details are on <https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query>. Try to name your meta\_query clauses, then order by them. Following code is untested: ``` $query = array( 'o...
81,893
<p>How do I use wp_enqueue_script so that I get protocol neutral URLs? Here is how I'm currently using it:</p> <p><code>&lt;?php wp_enqueue_script('name', get_bloginfo('template_directory'). '/js/name.pack.js'); ?&gt;</code></p> <p>I saw that <code>home_url()</code> is protocol aware so I figured <code>theme_url()</...
[ { "answer_id": 81897, "author": "webaware", "author_id": 24260, "author_profile": "https://wordpress.stackexchange.com/users/24260", "pm_score": 4, "selected": true, "text": "<p>You can't -- URLs must have a protocol for WordPress to enqueue them. What you can do, though, is detect which...
2013/01/16
[ "https://wordpress.stackexchange.com/questions/81893", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/23259/" ]
How do I use wp\_enqueue\_script so that I get protocol neutral URLs? Here is how I'm currently using it: `<?php wp_enqueue_script('name', get_bloginfo('template_directory'). '/js/name.pack.js'); ?>` I saw that `home_url()` is protocol aware so I figured `theme_url()` would be also but I'm getting the error below whe...
You can't -- URLs must have a protocol for WordPress to enqueue them. What you can do, though, is detect which protocol to use and then use that. ``` $protocol = is_ssl() ? 'https' : 'http'; $url = "$protocol://example.com/resource"; ``` But for enqueuing scripts from your theme, you should use [get\_template\_direc...
81,895
<p>I need to integrate <a href="http://kotowicz.net/jquery-option-tree/demo/demo.html" rel="nofollow">this plugin</a> with my WordPress site, and the categories must be in this format:</p> <pre><code> "Option 1": {"Suboption":200}, "Option 2": {"Suboption 2": {"Subsub 1":201, "Subsub 2":202}, "Subopt...
[ { "answer_id": 81908, "author": "Wyck", "author_id": 1509, "author_profile": "https://wordpress.stackexchange.com/users/1509", "pm_score": 1, "selected": true, "text": "<p>Here is a fast example using <code>get_categories</code> instead of a plugin or the walker class, maybe it will help...
2013/01/16
[ "https://wordpress.stackexchange.com/questions/81895", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/8124/" ]
I need to integrate [this plugin](http://kotowicz.net/jquery-option-tree/demo/demo.html) with my WordPress site, and the categories must be in this format: ``` "Option 1": {"Suboption":200}, "Option 2": {"Suboption 2": {"Subsub 1":201, "Subsub 2":202}, "Suboption 3": {"Subsub 3":203, "Subsub 4":204, ...
Here is a fast example using `get_categories` instead of a plugin or the walker class, maybe it will help you in the right direction, it will list all children of a parent category in json format. As brasofilo mentions since you require a specific format you will want to build a custom array. ``` // let's get the bare...
81,907
<p>I'm developing a plugin that uses custom capabilities. Some of those capabilities need to be added to all users who are super admins. Currently, I'm using this code:</p> <pre><code>$supers = get_super_admins(); foreach ( $supers as $admin ) { $user = new WP_User( 0, $admin ); $user-&gt;add_cap( 'my_cap' ); ...
[ { "answer_id": 81933, "author": "Mike Madern", "author_id": 24806, "author_profile": "https://wordpress.stackexchange.com/users/24806", "pm_score": -1, "selected": false, "text": "<p>The things to do:</p>\n\n<ol>\n<li>Get the author role.</li>\n<li>Add capability to that role.</li>\n</ol...
2013/01/17
[ "https://wordpress.stackexchange.com/questions/81907", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/19726/" ]
I'm developing a plugin that uses custom capabilities. Some of those capabilities need to be added to all users who are super admins. Currently, I'm using this code: ``` $supers = get_super_admins(); foreach ( $supers as $admin ) { $user = new WP_User( 0, $admin ); $user->add_cap( 'my_cap' ); $user->add_ca...
Although this isn't well documented, "Super Admin" is not a role (in that it is not an actual role object). It's more like a special "status". A list of users who are Super Admins (also called "network admins" or "site admins") are stored in a database site-option record called `site_admins`. Generally, adding a capab...