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
169,831
<p>What is the best way (performance &amp; code structure) to create a custom template for a WordPress Post, which belong to a specific category? I realized that you can’t just create <code>single-catname.php</code>.</p> <p>So far i tried two ways to change the template. But which one (or another one) is the best?</p>...
[ { "answer_id": 169862, "author": "Pieter Goosen", "author_id": 31545, "author_profile": "https://wordpress.stackexchange.com/users/31545", "pm_score": 5, "selected": true, "text": "<p>From my comment to the OP</p>\n<blockquote>\n<p>My opinion, use what you are comfortable with. If there ...
2014/11/29
[ "https://wordpress.stackexchange.com/questions/169831", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/45407/" ]
What is the best way (performance & code structure) to create a custom template for a WordPress Post, which belong to a specific category? I realized that you can’t just create `single-catname.php`. So far i tried two ways to change the template. But which one (or another one) is the best? **EDIT:** Any idea how to...
From my comment to the OP > > My opinion, use what you are comfortable with. If there are any performance difference it will be minute/irrelevant. My preference, use the filter > > > To come to your real concern/question, in my opinion, the best approach will be to use the parent category ID and work from there. ...
169,841
<p>I want to create a taxonomy that is related to the users, therefore I'd like to show the taxonomy under "Users" menu within wordpress admin. In codex there's a mention that you can attach taxonomy to "nav_menu_item" but I can't find any working example of how this works. If I use:</p> <pre><code>register_taxonomy( ...
[ { "answer_id": 169851, "author": "Madivad", "author_id": 37314, "author_profile": "https://wordpress.stackexchange.com/users/37314", "pm_score": 0, "selected": false, "text": "<p>The <code>register_taxonomy</code> function is designed only for adding taxonomies to existing post types and...
2014/11/29
[ "https://wordpress.stackexchange.com/questions/169841", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/57292/" ]
I want to create a taxonomy that is related to the users, therefore I'd like to show the taxonomy under "Users" menu within wordpress admin. In codex there's a mention that you can attach taxonomy to "nav\_menu\_item" but I can't find any working example of how this works. If I use: ``` register_taxonomy( 'expertise',...
The `register_taxonomy` function is designed only for adding taxonomies to existing post types and custom post types. It's not something that can be expanded to users. I have just tried a couple of plugins that work with taxonomies and neither are able to attach a taxonomy to a user. from <http://codex.wordpress.or...
169,847
<p>Using the <a href="https://wordpress.org/plugins/types/" rel="nofollow">WP Types Plugin</a>, I setup a custom post type (slug: <code>portfolio</code>), which has a custom taxonomy (slug: <code>portfolio-category</code>).</p> <p>The custom taxonomy has three items (slugs: <code>group1</code>, <code>group2</code>, <c...
[ { "answer_id": 169851, "author": "Madivad", "author_id": 37314, "author_profile": "https://wordpress.stackexchange.com/users/37314", "pm_score": 0, "selected": false, "text": "<p>The <code>register_taxonomy</code> function is designed only for adding taxonomies to existing post types and...
2014/11/29
[ "https://wordpress.stackexchange.com/questions/169847", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64156/" ]
Using the [WP Types Plugin](https://wordpress.org/plugins/types/), I setup a custom post type (slug: `portfolio`), which has a custom taxonomy (slug: `portfolio-category`). The custom taxonomy has three items (slugs: `group1`, `group2`, `group3`) to organize portfolio posts. On each single portfolio page I am display...
The `register_taxonomy` function is designed only for adding taxonomies to existing post types and custom post types. It's not something that can be expanded to users. I have just tried a couple of plugins that work with taxonomies and neither are able to attach a taxonomy to a user. from <http://codex.wordpress.or...
169,885
<p>I have this PHP code to generate a random numeric string:</p> <pre><code>function generateRandomString($length = 12) { global $generatedStrings; $characters = '0123456789'; $randomString = ''; for ($i = 0; $i &lt; $length; $i++) { $randomString .= $characters[rand(0, strlen($characters) - 1)...
[ { "answer_id": 169887, "author": "Hybrid Web Dev", "author_id": 36506, "author_profile": "https://wordpress.stackexchange.com/users/36506", "pm_score": 1, "selected": false, "text": "<pre><code>function wpse_18293_get_random_string ($number_of_chars_to_use) {\n\n $upper_case_characht...
2014/11/30
[ "https://wordpress.stackexchange.com/questions/169885", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64179/" ]
I have this PHP code to generate a random numeric string: ``` function generateRandomString($length = 12) { global $generatedStrings; $characters = '0123456789'; $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, strlen($characters) - 1)]; } if (...
``` function wpse_18293_get_random_string ($number_of_chars_to_use) { $upper_case_charachters = range('A', 'Z'); while($cnt < $number_of_chars_to_use) { $random_string.= $upper_case_charachters[mt_rand(0, count($upper_case_charachters)-1)]; $cnt++; } return $random_string } $rand...
169,941
<p>I am trying to wrap my head around custom post types. What I am trying to achieve is a simple branch listing. There is a dealers menu that has drop downs with regions. When you click on a region I just want it to list branches within the region. Nothing fancy, no maps, just plain text with branch name and contact de...
[ { "answer_id": 169960, "author": "Matej Đaković", "author_id": 31030, "author_profile": "https://wordpress.stackexchange.com/users/31030", "pm_score": 3, "selected": true, "text": "<p>You can do that easy on this way, just duplicate <code>single.php</code> and rename to <code>single-cust...
2014/12/01
[ "https://wordpress.stackexchange.com/questions/169941", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64184/" ]
I am trying to wrap my head around custom post types. What I am trying to achieve is a simple branch listing. There is a dealers menu that has drop downs with regions. When you click on a region I just want it to list branches within the region. Nothing fancy, no maps, just plain text with branch name and contact detai...
You can do that easy on this way, just duplicate `single.php` and rename to `single-custom-post-type-name.php` like `single-cars.php`, same thing with archive or taxonomy, `taxonomy-taxonomy-name.php` or `archive-taxonomy-name.php` Or you can make your query for random page, home or blog: ``` <?php // The Query $quer...
169,946
<p>i have added option box custom field in checkout page using bellow snippet hook's and function.when user order the product that option box custom field value displaying in backed admin panel but i am not able send that field in order email.</p> <p>The code or function for sending custom field value i have added in...
[ { "answer_id": 169951, "author": "Sanjay Nakate", "author_id": 39122, "author_profile": "https://wordpress.stackexchange.com/users/39122", "pm_score": 2, "selected": true, "text": "<p>Finally i got the answer i was wrong because i tried to send the variable you can not send the variable ...
2014/12/01
[ "https://wordpress.stackexchange.com/questions/169946", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/39122/" ]
i have added option box custom field in checkout page using bellow snippet hook's and function.when user order the product that option box custom field value displaying in backed admin panel but i am not able send that field in order email. The code or function for sending custom field value i have added in bottom si...
Finally i got the answer i was wrong because i tried to send the variable you can not send the variable you have to just put the name of custom field slug. In the bellow snippet i have replaced `$field` with my custom field name slug `_some_field` like:- `$keys['How did you learn about us?'] = '_some_field';` ``` /...
169,970
<p>I am trying to filter posts from category.</p> <p>This category is called "images"</p> <p>And I have the code below:</p> <pre><code>&lt;div id="owl-images" class="owl-carousel"&gt; &lt;?php query_posts('category_name=images'); ?&gt; &lt;?php if (have_posts()) : while (have_posts()) : the_post(); ...
[ { "answer_id": 169975, "author": "Axel De Acetis", "author_id": 25991, "author_profile": "https://wordpress.stackexchange.com/users/25991", "pm_score": 3, "selected": true, "text": "<p>In my opinion, you should avoid using common words like \"images\". It can be confusing for the system....
2014/12/01
[ "https://wordpress.stackexchange.com/questions/169970", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/63584/" ]
I am trying to filter posts from category. This category is called "images" And I have the code below: ``` <div id="owl-images" class="owl-carousel"> <?php query_posts('category_name=images'); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <?php $src = wp_get_...
In my opinion, you should avoid using common words like "images". It can be confusing for the system. A [previous post on SO](https://stackoverflow.com/questions/17470563/wordpress-get-featured-image-url-from-category) nailed the use of images using Category ID. Here's your edited code: ``` <?php $your_category_ID =...
169,976
<p>When Upload images from Editor and publish the post, I see for all images have link. How can remove it</p>
[ { "answer_id": 169981, "author": "Nicolai Grossherr", "author_id": 22534, "author_profile": "https://wordpress.stackexchange.com/users/22534", "pm_score": 0, "selected": false, "text": "<p>When inserting the image via the »Media Library« Modal, after clicking »Add Media«, select »None« f...
2014/12/01
[ "https://wordpress.stackexchange.com/questions/169976", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/82124/" ]
When Upload images from Editor and publish the post, I see for all images have link. How can remove it
This should do the trick. The filter will check for images and removes the a (link) tag. Just add it to your theme's functions.php: ``` add_filter( 'the_content', 'attachment_image_link_remove_filter' ); function attachment_image_link_remove_filter( $content ) { $content = preg_replace( array('{<a(.*?)(wp-att|w...
170,002
<p>I am trying to display all posts that are in a specific category and have a specific tag. This is what I have so far but it seems to ignore the &amp; and make it or.</p> <pre><code>&lt;?php $myposts = get_posts( "cat=the_field('troubleshooting_category')&amp;tag_id=5" ); foreach ( $myposts as $post ) : setup_postd...
[ { "answer_id": 170009, "author": "Pieter Goosen", "author_id": 31545, "author_profile": "https://wordpress.stackexchange.com/users/31545", "pm_score": 0, "selected": false, "text": "<p>As suggested in a comment, the best approach here will be to make use of a <a href=\"http://codex.wordp...
2014/12/01
[ "https://wordpress.stackexchange.com/questions/170002", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64237/" ]
I am trying to display all posts that are in a specific category and have a specific tag. This is what I have so far but it seems to ignore the & and make it or. ``` <?php $myposts = get_posts( "cat=the_field('troubleshooting_category')&tag_id=5" ); foreach ( $myposts as $post ) : setup_postdata( $post ); ?> <li><...
As suggested in a comment, the best approach here will be to make use of a [`tax_query`](http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters). You have much more flexibility and the ability to run more complex queries specially when you are working with more than one taxonomy (in this case `category...
170,007
<p>When a single post is clicked on from a category page or for that matter any page, you can get the URL of that referrer and parse it to get the query string. But this only works with the default permalink structure</p> <p>Example when the referrer is a category page:</p> <p>A <code>var_dump( parse_url( wp_get_refe...
[ { "answer_id": 170016, "author": "gmazzap", "author_id": 35541, "author_profile": "https://wordpress.stackexchange.com/users/35541", "pm_score": 4, "selected": true, "text": "<p>First of all I have to say that <code>wp_get_referer()</code> is not 100% reliable because it relies on <code>...
2014/12/01
[ "https://wordpress.stackexchange.com/questions/170007", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/31545/" ]
When a single post is clicked on from a category page or for that matter any page, you can get the URL of that referrer and parse it to get the query string. But this only works with the default permalink structure Example when the referrer is a category page: A `var_dump( parse_url( wp_get_referer() ) );` gives the ...
First of all I have to say that `wp_get_referer()` is not 100% reliable because it relies on `$_SERVER['HTTP_REFERER']` that is not 100% reliable, from [php.net](http://php.net/manual/en/reserved.variables.server.php) docs: > > The address of the page (if any) which referred the user agent to the current page. This i...
170,033
<p>Is there any way to grab the nav menu items as a multidimensional array instead of a flat array?</p> <p>By a tree-like structure I mean something that would preserve relationship between child and parent items, like so (this is just an example)…</p> <pre><code>array( array( 'post_type' =&gt; 'page', 'pos...
[ { "answer_id": 196038, "author": "birgire", "author_id": 26350, "author_profile": "https://wordpress.stackexchange.com/users/26350", "pm_score": 6, "selected": true, "text": "<p>The problem of <em>building a tree from a flat array</em> has been solved <a href=\"https://stackoverflow.com/...
2014/12/02
[ "https://wordpress.stackexchange.com/questions/170033", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/62519/" ]
Is there any way to grab the nav menu items as a multidimensional array instead of a flat array? By a tree-like structure I mean something that would preserve relationship between child and parent items, like so (this is just an example)… ``` array( array( 'post_type' => 'page', 'post_name' => 'Home', '...
The problem of *building a tree from a flat array* has been solved [here](https://stackoverflow.com/a/28429487/2078474) with this, slightly modified, recursive solution: ``` /** * Modification of "Build a tree from a flat array in PHP" * * Authors: @DSkinner, @ImmortalFirefly and @SteveEdson * * @link https://sta...
170,075
<p>I'm using a simple custom plugin that parses and saves external XML data as a serialized array in a custom field. This works fine, however, when I update the post, instead of the array I only see a message saying: "bool(false)". I guess it has to with serialize / unserialize but didn't find any clues.</p> <p>I need...
[ { "answer_id": 170183, "author": "Dipak G.", "author_id": 58180, "author_profile": "https://wordpress.stackexchange.com/users/58180", "pm_score": 2, "selected": false, "text": "<p>I have managed to fix it at my own.</p>\n\n<p>I have used following code to update post meta</p>\n\n<pre><co...
2014/12/02
[ "https://wordpress.stackexchange.com/questions/170075", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/58180/" ]
I'm using a simple custom plugin that parses and saves external XML data as a serialized array in a custom field. This works fine, however, when I update the post, instead of the array I only see a message saying: "bool(false)". I guess it has to with serialize / unserialize but didn't find any clues. I needed to seri...
I have managed to fix it at my own. I have used following code to update post meta ``` update_post_meta($post_id, 'tb_data', base64_encode(serialize($new_value_array))); ``` ...and following code to get post meta ``` $tb_meta = get_post_meta($post->ID, 'tb_data', true); $tb_meta_unserialized = unserialize(base64_d...
170,122
<p>I use a mixture of both <em>Bootstrap Glyphicons</em> and <em>WordPress Dashicons</em> in my <em>WordPress themes</em>.</p> <p>However, something which really bugs me is how the WordPress Dashicons don't seem to scale appropriately with different HTML elements (more specifically, variances of font sizes).</p> <p>I...
[ { "answer_id": 170125, "author": "coopersita", "author_id": 21258, "author_profile": "https://wordpress.stackexchange.com/users/21258", "pm_score": 0, "selected": false, "text": "<p>As I mentioned in my comment, the dashicons are meant to be part of the dashboard menu, as such they are s...
2014/12/02
[ "https://wordpress.stackexchange.com/questions/170122", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/9579/" ]
I use a mixture of both *Bootstrap Glyphicons* and *WordPress Dashicons* in my *WordPress themes*. However, something which really bugs me is how the WordPress Dashicons don't seem to scale appropriately with different HTML elements (more specifically, variances of font sizes). If you have a Heading 1 for example... ...
I took a look at Bootstrap's Glyphicon `CSS` and WordPress's Dashicon `CSS` and formulated a tweak. Bootstrap Glyphicons `CSS` -------------------------- ``` .glyphicon { position: relative; top: 1px; display: inline-block; font-family: 'Glyphicons Halflings'; font-style: normal; font-weight: ...
170,140
<p>I have a simple WP_Query:</p> <pre><code>$loop = new WP_Query(array( 'post_type' =&gt; array('image', 'video'), 'category_name' =&gt; $cat, 'meta_key'=&gt;'total_votes', 'orderby'=&gt;'date meta_value_num' )); </code></pre> <p>How can I alter this so that it return only videos with the ...
[ { "answer_id": 170141, "author": "tfrommen", "author_id": 27722, "author_profile": "https://wordpress.stackexchange.com/users/27722", "pm_score": 2, "selected": false, "text": "<p>Unfortunately, you can't. At least not with a single <code>WP_Query</code>, that is. What you could do, howe...
2014/12/02
[ "https://wordpress.stackexchange.com/questions/170140", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/9862/" ]
I have a simple WP\_Query: ``` $loop = new WP_Query(array( 'post_type' => array('image', 'video'), 'category_name' => $cat, 'meta_key'=>'total_votes', 'orderby'=>'date meta_value_num' )); ``` How can I alter this so that it return only videos with the tag `editor-pick` while still returni...
I happened to be working on something similar today and just remembered you were looking for something like this, so let me share it with you. Here's how one can use the `posts_where` filter to restrict the `WP_Query`, to posts in some custom post type *cpt1* OR another post type *cpt2* that's attached to some taxonom...
170,144
<p>here is the deal...</p> <p>I got hold of this piece of code to change the default post type shown on my TwentyTen child theme's homepage. It works like a charm when I add this code to the functions.php file, but I would like to also limit the number of posts to 1 (or 2) instead of the default 10 as in "Settings" se...
[ { "answer_id": 170145, "author": "kraftner", "author_id": 47733, "author_profile": "https://wordpress.stackexchange.com/users/47733", "pm_score": 2, "selected": true, "text": "<p>This should do the trick:</p>\n\n<pre><code>add_action( 'pre_get_posts', 'add_tours_post_type_to_query' );\n\...
2014/12/02
[ "https://wordpress.stackexchange.com/questions/170144", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/63185/" ]
here is the deal... I got hold of this piece of code to change the default post type shown on my TwentyTen child theme's homepage. It works like a charm when I add this code to the functions.php file, but I would like to also limit the number of posts to 1 (or 2) instead of the default 10 as in "Settings" section. Wh...
This should do the trick: ``` add_action( 'pre_get_posts', 'add_tours_post_type_to_query' ); function add_tours_post_type_to_query( $query ) { if ( is_home() && $query->is_main_query() ){ $query->set( 'post_type', array( 'tours' ) ); $query->set( 'posts_per_page', 1 ); } return $query; } ``` For the...
170,179
<p>all, I'm having a problem with my wordpress page while using encrypted $_GET parameters to obtain data. this is my function:</p> <pre><code>function encryptDecrypt($key, $string, $decrypt) { if($decrypt) { $decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($string), MCRY...
[ { "answer_id": 170180, "author": "john23klipp", "author_id": 43756, "author_profile": "https://wordpress.stackexchange.com/users/43756", "pm_score": 0, "selected": false, "text": "<p>first off; turn the wp_debug function on if you haven't already. (wp_config.php). This should give you so...
2014/12/03
[ "https://wordpress.stackexchange.com/questions/170179", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/63722/" ]
all, I'm having a problem with my wordpress page while using encrypted $\_GET parameters to obtain data. this is my function: ``` function encryptDecrypt($key, $string, $decrypt) { if($decrypt) { $decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($string), MCRYPT_MODE_CBC, ...
As the OP found out, `m` is a reserved parameter name that should be use only by core (indicates month). Solution is to use some other parameter name (always use your own prefixes in all global contexts!).
170,202
<p>After reading many question and answers and many had asked the same question I have been following the same instruction as the people instructed but my bad it's not working I have used </p> <ul> <li>dbDelta($sql)</li> <li>$wpdb->query($sql)</li> </ul> <p>It's not working</p> <p>sample code</p> <pre><code>&lt;?ph...
[ { "answer_id": 170203, "author": "shanebp", "author_id": 16575, "author_profile": "https://wordpress.stackexchange.com/users/16575", "pm_score": 3, "selected": true, "text": "<p>Your dot and quote notation is funky. Try this:</p>\n\n<pre><code>if($wpdb-&gt;get_var(\"SHOW TABLES LIKE '$ta...
2014/12/03
[ "https://wordpress.stackexchange.com/questions/170202", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60858/" ]
After reading many question and answers and many had asked the same question I have been following the same instruction as the people instructed but my bad it's not working I have used * dbDelta($sql) * $wpdb->query($sql) It's not working sample code ``` <?php /* Plugin Name: ContactUs Plugin URI: Description: Si...
Your dot and quote notation is funky. Try this: ``` if($wpdb->get_var("SHOW TABLES LIKE '$table_name'" ) != $table_name){ $sql= "CREATE TABLE $table_name ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, firstname VARCHAR(30) NOT NULL, lastname VARCHAR(30) NOT NULL, emai...
170,228
<p>I think I'm echoing the value of the selected option from my select meta box wrongly. Nothing is being shown in the browser.</p> <p><strong>Functions.php</strong> :</p> <pre><code>function add_custom_meta_box() { add_meta_box( 'custom_meta_box', 'Custom Meta Box', 'show_custom_meta_box...
[ { "answer_id": 170237, "author": "Community", "author_id": -1, "author_profile": "https://wordpress.stackexchange.com/users/-1", "pm_score": 0, "selected": false, "text": "<p>The following works:</p>\n\n<pre><code>$post_meta_data = get_post_custom($post-&gt;ID);\necho $post_meta_data['cu...
2014/12/03
[ "https://wordpress.stackexchange.com/questions/170228", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/-1/" ]
I think I'm echoing the value of the selected option from my select meta box wrongly. Nothing is being shown in the browser. **Functions.php** : ``` function add_custom_meta_box() { add_meta_box( 'custom_meta_box', 'Custom Meta Box', 'show_custom_meta_box', 'post', 'norm...
I got your "broken" code in your answer to work and will explain why. First, here's the edited code that wasn't working for you: ``` <?php //Get your post ID with a variable $this_post_id = get_the_ID(); //Removed get function from get_post_meta to make functionality clearer //I tend to avoid nesting...
170,243
<p>I have a custom post type called <code>rock</code> with a custom taxonomy called <code>genero</code>. <code>taxonomy-genero-curiosity.php</code> </p> <blockquote> <p>mypage/Rock/curiosity/ </p> </blockquote> <p>When i click subsequent paginated page links (e.g. [2], [3], [next]) </p> <blockquote> <p>mypage/Ro...
[ { "answer_id": 170247, "author": "shanebp", "author_id": 16575, "author_profile": "https://wordpress.stackexchange.com/users/16575", "pm_score": 1, "selected": false, "text": "<p>Try calling the nav before you reset the query.</p>\n\n<pre><code>...\n\nif (function_exists('wp_pagenavi')) ...
2014/12/03
[ "https://wordpress.stackexchange.com/questions/170243", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/54649/" ]
I have a custom post type called `rock` with a custom taxonomy called `genero`. `taxonomy-genero-curiosity.php` > > mypage/Rock/curiosity/ > > > When i click subsequent paginated page links (e.g. [2], [3], [next]) > > mypage/Rock/curiosity/page/2 > > > takes me to an 404 page. ``` <?php $paged = ( ...
Your problem is definitly your custom query. There are a problem or two with your custom query which I will not handle now. You should work through [this page (`WP_Query`)](http://codex.wordpress.org/Class_Reference/WP_Query) on how to properly construct a custom query Your real issue here is, and the question you mu...
170,252
<p>I have a widget in the sidebar that shows recent posts. The code below works to set the number of posts per page in each category, but it also affects the sidebar. Is there any way to exclude the sidebar?</p> <pre><code>/** Different number of posts per page depending on the category **/ function hwl_home_pagesize(...
[ { "answer_id": 170253, "author": "tfrommen", "author_id": 27722, "author_profile": "https://wordpress.stackexchange.com/users/27722", "pm_score": 2, "selected": true, "text": "<p>Check for <code>is_main_query</code> on the query object.</p>\n\n<pre><code>if ( is_category( 'video' ) &amp;...
2014/12/03
[ "https://wordpress.stackexchange.com/questions/170252", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18862/" ]
I have a widget in the sidebar that shows recent posts. The code below works to set the number of posts per page in each category, but it also affects the sidebar. Is there any way to exclude the sidebar? ``` /** Different number of posts per page depending on the category **/ function hwl_home_pagesize( $query ) { ...
Check for `is_main_query` on the query object. ``` if ( is_category( 'video' ) && $query->is_main_query() ) ```
170,264
<p>Many people has asked the same question, I have read those things and mine is different, </p> <p>I am trying to insert some values inside the database from the form but it's not getting inserted</p> <p>I have a table in the database having 6 columns wanted to insert some values inside only of 4 columns</p> <p><st...
[ { "answer_id": 170272, "author": "Mayeenul Islam", "author_id": 22728, "author_profile": "https://wordpress.stackexchange.com/users/22728", "pm_score": 0, "selected": false, "text": "<p>You have to do it yourself. It's just a frame of what it should be at least. Search more and use the f...
2014/12/04
[ "https://wordpress.stackexchange.com/questions/170264", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60858/" ]
Many people has asked the same question, I have read those things and mine is different, I am trying to insert some values inside the database from the form but it's not getting inserted I have a table in the database having 6 columns wanted to insert some values inside only of 4 columns **Table Name: wp\_contactus...
I figured out my error in the query, Thank you all guys for responding, I just gave the piece of code ``` <?php global $wpdb; $contactus_table = $wpdb->prefix."contactus"; //error with the query $sql = "INSERT INTO $contactus_table (firstname, lastname, email, query, reg_date) VALUES ('$firstNam...
170,274
<p>I'm currently learning Wordpress.</p> <p>So my theme has a custom post type called <strong>portfolio</strong>. I'm using this online code to add a custom taxonomy to this portfolio custom type:</p> <pre><code>function add_custom_taxonomies() { // Add new "Locations" taxonomy register_taxonomy('location', 'port...
[ { "answer_id": 170275, "author": "Kamil", "author_id": 5874, "author_profile": "https://wordpress.stackexchange.com/users/5874", "pm_score": 0, "selected": false, "text": "<p>If you don't see template content after create new taxonomy or cpt maybe you could try to refresh your permalinks...
2014/12/04
[ "https://wordpress.stackexchange.com/questions/170274", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60560/" ]
I'm currently learning Wordpress. So my theme has a custom post type called **portfolio**. I'm using this online code to add a custom taxonomy to this portfolio custom type: ``` function add_custom_taxonomies() { // Add new "Locations" taxonomy register_taxonomy('location', 'portfolio_page', array( // Hierarc...
A hierarchical custom taxonomy works is the same exact way as would the build-in taxonomy `category`. On the other hand, non hierarchical taxonomies would work exactly like the build-in taxonomy `post_tag` You have to add terms to your taxonomy in the same way as you would add "categories" in the category screen back ...
170,288
<p>Any ideas why <code>define('FORCE_SSL_ADMIN', true);</code> wouldn't work?</p> <p>I'm not getting any errors at all, but a <code>http</code> request to <code>example.com/wp-admin</code> isn't redirecting to <code>https</code></p>
[ { "answer_id": 170289, "author": "bsmoo", "author_id": 64373, "author_profile": "https://wordpress.stackexchange.com/users/64373", "pm_score": 3, "selected": true, "text": "<p>Just figured it out... It was the positioning of the define statement.</p>\n\n<p>I added the below above the <co...
2014/12/04
[ "https://wordpress.stackexchange.com/questions/170288", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64373/" ]
Any ideas why `define('FORCE_SSL_ADMIN', true);` wouldn't work? I'm not getting any errors at all, but a `http` request to `example.com/wp-admin` isn't redirecting to `https`
Just figured it out... It was the positioning of the define statement. I added the below above the `/* That's all, stop editing! Happy blogging. */` line ``` define('FORCE_SSL_ADMIN', true); define('FORCE_SSL_LOGIN', true); ``` Thanks!
170,311
<p>As of WordPress 3.9, <a href="https://make.wordpress.org/core/2014/04/15/html5-galleries-captions-in-wordpress-3-9/" rel="nofollow">WordPress generates HTML5 Galleries</a> if HTML5 is supported in the theme:</p> <p><code>add_theme_support( 'html5' );</code></p> <p>Originally in my theme development I did not dec...
[ { "answer_id": 170289, "author": "bsmoo", "author_id": 64373, "author_profile": "https://wordpress.stackexchange.com/users/64373", "pm_score": 3, "selected": true, "text": "<p>Just figured it out... It was the positioning of the define statement.</p>\n\n<p>I added the below above the <co...
2014/12/04
[ "https://wordpress.stackexchange.com/questions/170311", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/7355/" ]
As of WordPress 3.9, [WordPress generates HTML5 Galleries](https://make.wordpress.org/core/2014/04/15/html5-galleries-captions-in-wordpress-3-9/) if HTML5 is supported in the theme: `add_theme_support( 'html5' );` Originally in my theme development I did not declare HTML5 support and I've already published a few gall...
Just figured it out... It was the positioning of the define statement. I added the below above the `/* That's all, stop editing! Happy blogging. */` line ``` define('FORCE_SSL_ADMIN', true); define('FORCE_SSL_LOGIN', true); ``` Thanks!
170,316
<p><strong>My goal is this:</strong></p> <p>I've added an additional metabox to my post page. Within this metabox there are multiple checkboxes. Each checkbox is associated with a person's name. The idea is that, if a person is featured in the post, I'll check the box associated with their name. For each checked box, ...
[ { "answer_id": 182699, "author": "Miles Fonda", "author_id": 59918, "author_profile": "https://wordpress.stackexchange.com/users/59918", "pm_score": 2, "selected": false, "text": "<p>I was racking my brains out with this too and was finally able to find a solution that works. This should...
2014/12/04
[ "https://wordpress.stackexchange.com/questions/170316", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64386/" ]
**My goal is this:** I've added an additional metabox to my post page. Within this metabox there are multiple checkboxes. Each checkbox is associated with a person's name. The idea is that, if a person is featured in the post, I'll check the box associated with their name. For each checked box, an image of each person...
I was racking my brains out with this too and was finally able to find a solution that works. This should work for you, I've tested quickly. I'll present it in 3 parts: **PART 1: ADD THE CUSTOM META BOX** ``` add_action( 'add_meta_boxes', 'add_custom_box' ); function add_custom_box( $post ) { add_meta_bo...
170,353
<p>Hello WordPress developers. Over the years, I've found answers to many questions I've had with WordPress. I want to thank you for your help. Today, I have a question myself, and seek for expert advice.</p> <p>I'm building a site for a movie theatre. I have a custom post type <strong>movies</strong>. I'm using <a hr...
[ { "answer_id": 173534, "author": "Jono Alderson", "author_id": 3601, "author_profile": "https://wordpress.stackexchange.com/users/3601", "pm_score": 1, "selected": false, "text": "<p>This is a deceptively complex question; it's specifically about ordering by <strong>contextual</strong> d...
2014/12/05
[ "https://wordpress.stackexchange.com/questions/170353", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64376/" ]
Hello WordPress developers. Over the years, I've found answers to many questions I've had with WordPress. I want to thank you for your help. Today, I have a question myself, and seek for expert advice. I'm building a site for a movie theatre. I have a custom post type **movies**. I'm using [Types](http://wp-types.com/...
1) Using only the `posts_orderby` filter: ----------------------------------------- It looks like you want to order the *movies* by the **minimum** of the `wpcf-showtime` meta values. You can modify the `ORDER BY` part of the SQL generated by the `WP_Query`, by using the `posts_orderby` filter. Here's an example: ...
170,358
<p>I am trying to understand when and why I should use the global $post variable. I have tried to do the following on a post page, outside the loop, and as expected it works.</p> <pre><code> &lt;?php global $post; echo $post-&gt;ID; ?&gt; </code></pre> <p>If I do the same on an archive page (j...
[ { "answer_id": 170363, "author": "NateWr", "author_id": 39309, "author_profile": "https://wordpress.stackexchange.com/users/39309", "pm_score": 5, "selected": true, "text": "<p>This is perhaps too broad a question to answer well. The <code>$post</code> global <em>could</em> be used in al...
2014/12/05
[ "https://wordpress.stackexchange.com/questions/170358", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/14378/" ]
I am trying to understand when and why I should use the global $post variable. I have tried to do the following on a post page, outside the loop, and as expected it works. ``` <?php global $post; echo $post->ID; ?> ``` If I do the same on an archive page (just wanted to see what happens), fo...
This is perhaps too broad a question to answer well. The `$post` global *could* be used in all sorts of ways. Whether or not it *should* be used depends on each circumstance. However, as I understand it, the **main intended purpose** of the `$post` global is its use in theme template files. When you use `the_title()...
170,397
<p>If you click "Increase indent" in the visual editor it adds the following code into the text editor:</p> <pre><code>&lt;p style="padding-left:30px;"&gt; </code></pre> <p>How to change it to <code>text-indent: 30px;</code> not affecting the core files?</p> <p>I searched in a lot of files and didn't found any piece...
[ { "answer_id": 170402, "author": "Shawn", "author_id": 35677, "author_profile": "https://wordpress.stackexchange.com/users/35677", "pm_score": 0, "selected": false, "text": "<p>This might guide you in the right direction:</p>\n\n<p><a href=\"http://codex.wordpress.org/TinyMCE_Custom_Butt...
2014/12/05
[ "https://wordpress.stackexchange.com/questions/170397", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/45476/" ]
If you click "Increase indent" in the visual editor it adds the following code into the text editor: ``` <p style="padding-left:30px;"> ``` How to change it to `text-indent: 30px;` not affecting the core files? I searched in a lot of files and didn't found any piece of code that would be responsible for that. Than...
You need to modify the TinyMCE settings object on instantiation: Reference: [TinyMCE documentation - content formatting](https://www.tinymce.com/docs/configure/content-formatting/#indentation) WordPress provides a filter for this very purpose called [`tiny_mce_before_init`](http://codex.wordpress.org/Plugin_API/Filte...
170,410
<p>I am using ajax to submit log in and log out credentials. The log in and log out forms are replaced with html returned by a successful response. No page loading is happening page content is loaded via an ajax get request upon successful log in or log out.</p> <p>I can successfully log in and then log out, but when ...
[ { "answer_id": 170438, "author": "Rarst", "author_id": 847, "author_profile": "https://wordpress.stackexchange.com/users/847", "pm_score": 2, "selected": true, "text": "<p>I hadn't run your code, but my educated guess is that the fault in your code flow is that nonces are user specific. ...
2014/12/05
[ "https://wordpress.stackexchange.com/questions/170410", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/10907/" ]
I am using ajax to submit log in and log out credentials. The log in and log out forms are replaced with html returned by a successful response. No page loading is happening page content is loaded via an ajax get request upon successful log in or log out. I can successfully log in and then log out, but when I attempt ...
I hadn't run your code, but my educated guess is that the fault in your code flow is that nonces are user specific. While anonymous nonce is possible, it is useless for its purpose because it would be same for *all* anonymous users. So there is likely mismatch somewhere and you are trying to use nonce of specific user...
170,445
<p>In my sidebar i would like show archieves list month exclude 'banner' category post. Below codes are tried, but not work for me. </p> <pre><code> &lt;?php echo wp_get_archives('type=monthly&amp;exclude=6&amp;limit=5'); ?&gt; &lt;?php echo wp_get_archives( array( 'type' =&gt; 'monthly', 'exclude' =&gt; 6,'limit...
[ { "answer_id": 170461, "author": "Pieter Goosen", "author_id": 31545, "author_profile": "https://wordpress.stackexchange.com/users/31545", "pm_score": 2, "selected": false, "text": "<p>Your code won't work as there are no <code>exclude</code> parameter in <a href=\"http://codex.wordpress...
2014/12/06
[ "https://wordpress.stackexchange.com/questions/170445", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64463/" ]
In my sidebar i would like show archieves list month exclude 'banner' category post. Below codes are tried, but not work for me. ``` <?php echo wp_get_archives('type=monthly&exclude=6&limit=5'); ?> <?php echo wp_get_archives( array( 'type' => 'monthly', 'exclude' => 6,'limit' => 5) ); ?> <?php $args = array...
Notice that you don't need `echo` to display the result, since `echo=1` is the default settings of `wp_get_archives()`. As @PieterGoosen [explained](https://wordpress.stackexchange.com/a/170461/26350), the `wp_get_archives()` function doesn't support the `exclude` parameter. But we can use `_exclude_terms`, the *cust...
170,450
<p>I want to sort posts by alphabet in local language (croatian language). </p> <p>So letter Đ should come after D but now it goes in the end, after Z. Some letters (like Č and Ć) should come after C, but currently Wordpress is sorting them like they all are under C.</p> <p>I am using localized Wordpress version (4.0...
[ { "answer_id": 170453, "author": "Sagive", "author_id": 7990, "author_profile": "https://wordpress.stackexchange.com/users/7990", "pm_score": 0, "selected": false, "text": "<p>If Wordpress is installed in your language, that shouldn't be a problem. </p>\n\n<p>You are missing the order p...
2014/12/06
[ "https://wordpress.stackexchange.com/questions/170450", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/47357/" ]
I want to sort posts by alphabet in local language (croatian language). So letter Đ should come after D but now it goes in the end, after Z. Some letters (like Č and Ć) should come after C, but currently Wordpress is sorting them like they all are under C. I am using localized Wordpress version (4.0.1–hr) and the qu...
I managed to make it work: In `wpconfig.php` file I set ``` define('DB_COLLATE', 'utf8_croatian_ci'); ``` Do an SQL query on database in PhpMyadmin with: ``` ALTER TABLE wp_posts CONVERT TO CHARACTER SET utf8 COLLATE utf8_croatian_ci ``` I tried setting with `utf8_unicode_ci` first, sorting was slightly better ...
170,474
<p>I am attempting to disable the Text tab in the post editor but not having any luck.</p> <p><img src="https://i.stack.imgur.com/RXIqq.png" alt="enter image description here"></p> <p>The first thing I want to do is set the Visual editor to be the default but this code does not work (it is being called from a MU plug...
[ { "answer_id": 170479, "author": "Adam", "author_id": 37125, "author_profile": "https://wordpress.stackexchange.com/users/37125", "pm_score": 3, "selected": false, "text": "<p>I was able to resolve both defaulting to the Visual editor and hiding the tabs with the following code.</p>\n\n<...
2014/12/07
[ "https://wordpress.stackexchange.com/questions/170474", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/37125/" ]
I am attempting to disable the Text tab in the post editor but not having any luck. ![enter image description here](https://i.stack.imgur.com/RXIqq.png) The first thing I want to do is set the Visual editor to be the default but this code does not work (it is being called from a MU plugin): ``` apply_filters( 'wp_de...
I was able to resolve both defaulting to the Visual editor and hiding the tabs with the following code. Dumped the following in plugin file: ``` add_filter( 'wp_default_editor', array($this, 'default_editor') ); ``` Hide the tabs with this javascript: ``` $('.wp-editor-tabs').remove(); ``` Or hide it with CSS: ...
170,509
<p>I have a plugin where I am creating a shortcode that creates a form with a textarea field. I would like the user to be able to insert a complete HTML page into the editor - including the HTML and BODY tags and allow all HTML tags. Whenever I switch from Text to Visual view, paragraph tags get added and all but the H...
[ { "answer_id": 170520, "author": "Céline Garel", "author_id": 17456, "author_profile": "https://wordpress.stackexchange.com/users/17456", "pm_score": 3, "selected": false, "text": "<p>Try this function from <a href=\"http://www.leighton.com/blog/stop-tinymce-in-wordpress-3-x-messing-up-y...
2014/12/07
[ "https://wordpress.stackexchange.com/questions/170509", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/20453/" ]
I have a plugin where I am creating a shortcode that creates a form with a textarea field. I would like the user to be able to insert a complete HTML page into the editor - including the HTML and BODY tags and allow all HTML tags. Whenever I switch from Text to Visual view, paragraph tags get added and all but the H1 t...
Try this function from [leighton.com](http://www.leighton.com/blog/stop-tinymce-in-wordpress-3-x-messing-up-your-html-code) : ``` function override_mce_options($initArray) { $opts = '*[*]'; $initArray['valid_elements'] = $opts; $initArray['extended_valid_elements'] = $opts; return $initArray; } add_fil...
170,540
<p>In mysql or mysqli you can add this type of Query:</p> <pre><code>&lt;?php $sql = mysqli_query($con, Insert into database itt (name) VALUES ($name)") or die(mysqli_error($con)); ?&gt; </code></pre> <p>What does wordpress do for this?</p> <p>Or how does the code look?</p> <p>Does it look like the code above...
[ { "answer_id": 170520, "author": "Céline Garel", "author_id": 17456, "author_profile": "https://wordpress.stackexchange.com/users/17456", "pm_score": 3, "selected": false, "text": "<p>Try this function from <a href=\"http://www.leighton.com/blog/stop-tinymce-in-wordpress-3-x-messing-up-y...
2014/12/08
[ "https://wordpress.stackexchange.com/questions/170540", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64500/" ]
In mysql or mysqli you can add this type of Query: ``` <?php $sql = mysqli_query($con, Insert into database itt (name) VALUES ($name)") or die(mysqli_error($con)); ?> ``` What does wordpress do for this? Or how does the code look? Does it look like the code above?
Try this function from [leighton.com](http://www.leighton.com/blog/stop-tinymce-in-wordpress-3-x-messing-up-your-html-code) : ``` function override_mce_options($initArray) { $opts = '*[*]'; $initArray['valid_elements'] = $opts; $initArray['extended_valid_elements'] = $opts; return $initArray; } add_fil...
170,544
<p>I'm trying to dequeue some scripts from a plugin that I only need for the home page. For the home page, I'm using a file called <code>front-page.php</code> with this on top to make it a <code>home</code> template:</p> <pre><code>&lt;?php /* Template Name: Home */ ?&gt; </code></pre> <p>The function is removing the...
[ { "answer_id": 170545, "author": "Desi", "author_id": 18320, "author_profile": "https://wordpress.stackexchange.com/users/18320", "pm_score": 1, "selected": false, "text": "<p>Never mind, I figured it out through another way:</p>\n\n<pre><code>add_action( 'wp_print_scripts', 'my_deregist...
2014/12/08
[ "https://wordpress.stackexchange.com/questions/170544", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18320/" ]
I'm trying to dequeue some scripts from a plugin that I only need for the home page. For the home page, I'm using a file called `front-page.php` with this on top to make it a `home` template: ``` <?php /* Template Name: Home */ ?> ``` The function is removing the scripts, but it's removing them on all pages. I want ...
Just a few notes on your code * You should dequeue and deregister a script to remove it completely from the `$wp_scripts` global * You should not be using `wp_print_scripts`, this is the wrong hook. You should be using `wp_enqueue_scripts` * Don't wrap your action in a conditional. Your conditional tag might either be...
170,546
<p>I want to be able to upload a 1000 x 1000px image as a featured image on a post but then be able to crop it to the required featured image size. Any way to enable this?</p>
[ { "answer_id": 170545, "author": "Desi", "author_id": 18320, "author_profile": "https://wordpress.stackexchange.com/users/18320", "pm_score": 1, "selected": false, "text": "<p>Never mind, I figured it out through another way:</p>\n\n<pre><code>add_action( 'wp_print_scripts', 'my_deregist...
2014/12/08
[ "https://wordpress.stackexchange.com/questions/170546", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/24032/" ]
I want to be able to upload a 1000 x 1000px image as a featured image on a post but then be able to crop it to the required featured image size. Any way to enable this?
Just a few notes on your code * You should dequeue and deregister a script to remove it completely from the `$wp_scripts` global * You should not be using `wp_print_scripts`, this is the wrong hook. You should be using `wp_enqueue_scripts` * Don't wrap your action in a conditional. Your conditional tag might either be...
170,549
<p>I am new to wordpress development &amp; tried to learning plugin development.I have created a custom table from which i want to show the number of records found.I have tried the below code but it always shows 1 as a result irrespective of number of rows in a table.</p> <pre><code>//To show number of rows in table ...
[ { "answer_id": 170550, "author": "Mayeenul Islam", "author_id": 22728, "author_profile": "https://wordpress.stackexchange.com/users/22728", "pm_score": 1, "selected": false, "text": "<h3>WAY #1</h3>\n\n<p>You can use the WordPress way using <a href=\"http://codex.wordpress.org/Class_Refe...
2014/12/08
[ "https://wordpress.stackexchange.com/questions/170549", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64505/" ]
I am new to wordpress development & tried to learning plugin development.I have created a custom table from which i want to show the number of records found.I have tried the below code but it always shows 1 as a result irrespective of number of rows in a table. ``` //To show number of rows in table function DB_Tab...
Why don't you directly echo the $num as it will contain the count of rows already...Here's the edited part.. ``` //To show number of rows in table function DB_Tables_Rows() { global $wpdb; $table_name = $wpdb->prefix . 'mydata'; $count_query = "select count(*) from $table_name"; $num = $wpdb->get_var...
170,595
<p>Although this could be opinion based, there must be a some consistent way / optimised way of manipulating data from a <code>WP_Query</code>. For example, the 'best' way to get a posts title?</p> <pre><code>$query = new WP_Query($args); if ($query-&gt;have_posts()) { while ($query-&gt;have_posts()) { ...
[ { "answer_id": 170596, "author": "Howdy_McGee", "author_id": 7355, "author_profile": "https://wordpress.stackexchange.com/users/7355", "pm_score": 3, "selected": true, "text": "<p>All 3 of these <em>could</em> do the same thing, it's just a matter of how you want to use them.</p>\n\n<p><...
2014/12/08
[ "https://wordpress.stackexchange.com/questions/170595", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/51823/" ]
Although this could be opinion based, there must be a some consistent way / optimised way of manipulating data from a `WP_Query`. For example, the 'best' way to get a posts title? ``` $query = new WP_Query($args); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $...
All 3 of these *could* do the same thing, it's just a matter of how you want to use them. `the_title()` calls `get_the_title()` which gets the title by `$post->post_title`. [View `the_title()` Source on Trac](https://core.trac.wordpress.org/browser/tags/4.0/src/wp-includes/post-template.php#L43) [View `get_the_title...
170,619
<p>I'm using this code to display widgets of certain sidebar:</p> <pre><code>$sidebar_id = 'sidebar1'; $sidebars_widgets = wp_get_sidebars_widgets(); $widget_ids = $sidebars_widgets[$sidebar_id]; foreach( $widget_ids as $id ) { echo '&lt;li&gt;&lt;a href="#'.$id.'"&gt;'.$id['title'].'&lt;/a&gt;&lt;/li&gt;'; }...
[ { "answer_id": 170624, "author": "RachieVee", "author_id": 42783, "author_profile": "https://wordpress.stackexchange.com/users/42783", "pm_score": 0, "selected": false, "text": "<p>If you want to just display all the widgets coming from a specific sidebar, try <a href=\"http://codex.word...
2014/12/08
[ "https://wordpress.stackexchange.com/questions/170619", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/37529/" ]
I'm using this code to display widgets of certain sidebar: ``` $sidebar_id = 'sidebar1'; $sidebars_widgets = wp_get_sidebars_widgets(); $widget_ids = $sidebars_widgets[$sidebar_id]; foreach( $widget_ids as $id ) { echo '<li><a href="#'.$id.'">'.$id['title'].'</a></li>'; } ``` I'm trying to display the widge...
Found a 'dirty' way to do it: Here's my code: ``` $sidebar_id = 'sidebar1'; $sidebars_widgets = wp_get_sidebars_widgets(); $widget_ids = $sidebars_widgets[$sidebar_id]; foreach( $widget_ids as $id ) { $wdgtvar = 'widget_'._get_widget_id_base( $id ); $idvar = _get_widget_id_base( $id ); $i...
170,620
<p>I wanted to create an admin menu in WordPress that does not go to a page when you click it. The Menu would be as follows.</p> <pre><code>Members &lt;-- Top Level View Members Add Members </code></pre> <p>"Members", the top level menu, would not link to anywhere. It just holds the other menu items.</p> <p>The re...
[ { "answer_id": 170629, "author": "kaiser", "author_id": 385, "author_profile": "https://wordpress.stackexchange.com/users/385", "pm_score": 3, "selected": true, "text": "<p>You can use <a href=\"http://codex.wordpress.org/Function_Reference/add_menu_page\" rel=\"nofollow noreferrer\"><co...
2014/12/08
[ "https://wordpress.stackexchange.com/questions/170620", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64536/" ]
I wanted to create an admin menu in WordPress that does not go to a page when you click it. The Menu would be as follows. ``` Members <-- Top Level View Members Add Members ``` "Members", the top level menu, would not link to anywhere. It just holds the other menu items. The reason WHY, is that different users will...
You can use [`add_menu_page()`](http://codex.wordpress.org/Function_Reference/add_menu_page) to add the link yourself. Simply use `#` as menu slug. You can then use [`add_submenu_page()`](http://codex.wordpress.org/Function_Reference/add_submenu_page) to add the other menu items yourself. Another option would be to t...
170,628
<p>I'm trying to create a role that restricts the ability to post to a specific category, hiding the other from the checkbox.</p> <p>I don't want to use plugins. I'm looking for a snippet to put in functions.php. I checked all the questions/blog posts about this and no solutions worked.</p> <p>I think this is the sta...
[ { "answer_id": 170629, "author": "kaiser", "author_id": 385, "author_profile": "https://wordpress.stackexchange.com/users/385", "pm_score": 3, "selected": true, "text": "<p>You can use <a href=\"http://codex.wordpress.org/Function_Reference/add_menu_page\" rel=\"nofollow noreferrer\"><co...
2014/12/08
[ "https://wordpress.stackexchange.com/questions/170628", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/23296/" ]
I'm trying to create a role that restricts the ability to post to a specific category, hiding the other from the checkbox. I don't want to use plugins. I'm looking for a snippet to put in functions.php. I checked all the questions/blog posts about this and no solutions worked. I think this is the starting point.. `...
You can use [`add_menu_page()`](http://codex.wordpress.org/Function_Reference/add_menu_page) to add the link yourself. Simply use `#` as menu slug. You can then use [`add_submenu_page()`](http://codex.wordpress.org/Function_Reference/add_submenu_page) to add the other menu items yourself. Another option would be to t...
170,633
<p>I'm using a plugin called Exifography. They provide the <a href="http://www.kristarella.com/2012/07/filtering-exifography-output/" rel="nofollow">capability to use filters</a> to adjust for your purposes. In the example provided I'm simply trying to get the height &amp; width of the image and return it.</p> <p>Thi...
[ { "answer_id": 170629, "author": "kaiser", "author_id": 385, "author_profile": "https://wordpress.stackexchange.com/users/385", "pm_score": 3, "selected": true, "text": "<p>You can use <a href=\"http://codex.wordpress.org/Function_Reference/add_menu_page\" rel=\"nofollow noreferrer\"><co...
2014/12/09
[ "https://wordpress.stackexchange.com/questions/170633", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64488/" ]
I'm using a plugin called Exifography. They provide the [capability to use filters](http://www.kristarella.com/2012/07/filtering-exifography-output/) to adjust for your purposes. In the example provided I'm simply trying to get the height & width of the image and return it. This works great on the attachment page (ima...
You can use [`add_menu_page()`](http://codex.wordpress.org/Function_Reference/add_menu_page) to add the link yourself. Simply use `#` as menu slug. You can then use [`add_submenu_page()`](http://codex.wordpress.org/Function_Reference/add_submenu_page) to add the other menu items yourself. Another option would be to t...
170,641
<p>I have an option for my logged in users where they can hide the posts they dont want to see.</p> <p>Everything works as expected until I implement transients. When I set the transients to cache the posts queries, the posts are not hidden until the transients expire.</p> <p>So, what should I do? The only thing I ca...
[ { "answer_id": 170629, "author": "kaiser", "author_id": 385, "author_profile": "https://wordpress.stackexchange.com/users/385", "pm_score": 3, "selected": true, "text": "<p>You can use <a href=\"http://codex.wordpress.org/Function_Reference/add_menu_page\" rel=\"nofollow noreferrer\"><co...
2014/12/09
[ "https://wordpress.stackexchange.com/questions/170641", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/14128/" ]
I have an option for my logged in users where they can hide the posts they dont want to see. Everything works as expected until I implement transients. When I set the transients to cache the posts queries, the posts are not hidden until the transients expire. So, what should I do? The only thing I can think of is to ...
You can use [`add_menu_page()`](http://codex.wordpress.org/Function_Reference/add_menu_page) to add the link yourself. Simply use `#` as menu slug. You can then use [`add_submenu_page()`](http://codex.wordpress.org/Function_Reference/add_submenu_page) to add the other menu items yourself. Another option would be to t...
170,659
<p>I want to redirect an user and his user ID is 6. So I added this code into my <code>functions.php</code></p> <pre><code>if ( is_user_logged_in() ) { $user_id = get_current_user_id(); if ($user_id == 6) { /* redirect users to front page after login */ function redirect_to_front_page...
[ { "answer_id": 170660, "author": "shyammakwana.me", "author_id": 49267, "author_profile": "https://wordpress.stackexchange.com/users/49267", "pm_score": 1, "selected": false, "text": "<p>use <code>login_redirect</code> hook instead <code>login_form</code>\nAnd you can move conditions ins...
2014/12/09
[ "https://wordpress.stackexchange.com/questions/170659", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/43764/" ]
I want to redirect an user and his user ID is 6. So I added this code into my `functions.php` ``` if ( is_user_logged_in() ) { $user_id = get_current_user_id(); if ($user_id == 6) { /* redirect users to front page after login */ function redirect_to_front_page() { glob...
You need to use the `login_redirect` filter **returning** the redirect location: ``` add_filter( 'login_redirect', 'redirect_to_home', 10, 3 ); function redirect_to_home( $redirect_to, $request, $user ) { if( $user->ID == 6 ) { //If user ID is 6, redirect to home return get_home_url(); } else ...
170,663
<p>I am trying to remove a theme action for an elegant-themes theme using a child theme.. This works when I remove action after add_action code anywhere in the parent theme functions.php. However, it does not work when I add it from child theme functions.php. </p> <pre><code>remove_action ('after_setup_theme', 'et_pb_...
[ { "answer_id": 170665, "author": "cybmeta", "author_id": 37428, "author_profile": "https://wordpress.stackexchange.com/users/37428", "pm_score": 2, "selected": false, "text": "<p>The functions.php file of child themes is loaded right before the parent theme functions.php, so when you run...
2014/12/09
[ "https://wordpress.stackexchange.com/questions/170663", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64561/" ]
I am trying to remove a theme action for an elegant-themes theme using a child theme.. This works when I remove action after add\_action code anywhere in the parent theme functions.php. However, it does not work when I add it from child theme functions.php. ``` remove_action ('after_setup_theme', 'et_pb_setup_theme' ...
As @cybmeta already pointed out, you are too early with your removal. So you have to defer the actual removal, for instance like so: ``` add_action( 'after_setup_theme', 'wpdev_170663_remove_parent_theme_stuff', 0 ); function wpdev_170663_remove_parent_theme_stuff() { remove_action( 'after_setup_theme', 'et_pb_s...
170,679
<p>I have added custom fields by clicking on screen option and mark custom field ,how to display custom field value on page?</p>
[ { "answer_id": 170665, "author": "cybmeta", "author_id": 37428, "author_profile": "https://wordpress.stackexchange.com/users/37428", "pm_score": 2, "selected": false, "text": "<p>The functions.php file of child themes is loaded right before the parent theme functions.php, so when you run...
2014/12/09
[ "https://wordpress.stackexchange.com/questions/170679", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64566/" ]
I have added custom fields by clicking on screen option and mark custom field ,how to display custom field value on page?
As @cybmeta already pointed out, you are too early with your removal. So you have to defer the actual removal, for instance like so: ``` add_action( 'after_setup_theme', 'wpdev_170663_remove_parent_theme_stuff', 0 ); function wpdev_170663_remove_parent_theme_stuff() { remove_action( 'after_setup_theme', 'et_pb_s...
170,690
<p>In a post I want to place a custom image. how do i place a thumbnail with link to original image? below is my current code.</p> <pre><code>&lt;a href="[site_url]/wp-content/uploads/GABON-Leopard-Gas-Discovery-1x1.jpg"&gt;&lt;img class="alignright size-medium wp-image-5435" src="[site_url]/wp-content/uploads/GABON-L...
[ { "answer_id": 170705, "author": "skim-", "author_id": 25265, "author_profile": "https://wordpress.stackexchange.com/users/25265", "pm_score": 3, "selected": true, "text": "<p>If you know the image's ID :</p>\n\n<pre><code>wp_get_attachment_image( $image-&gt;ID, array(200, 112) );\n</cod...
2014/12/09
[ "https://wordpress.stackexchange.com/questions/170690", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/28537/" ]
In a post I want to place a custom image. how do i place a thumbnail with link to original image? below is my current code. ``` <a href="[site_url]/wp-content/uploads/GABON-Leopard-Gas-Discovery-1x1.jpg"><img class="alignright size-medium wp-image-5435" src="[site_url]/wp-content/uploads/GABON-Leopard-Gas-Discovery-1x...
If you know the image's ID : ``` wp_get_attachment_image( $image->ID, array(200, 112) ); ``` returns an HTML img element or empty string on failure. The entire code could be something like : ``` <a href="<?= get_attachment_link( '5435' ); ?>"> <?= wp_get_attachment_image( '5435', array(200, 112) ); ?> </a> ```
170,736
<p>I'm using wordpress 4 and want the fullscreen page editor to be just as wide as the text of my page. eg 1024px.</p> <p>I tried setting #wp-fullscreen-wrap in my css and the dfw_width option but they all seem to be ignored.</p>
[ { "answer_id": 170746, "author": "Medardaosa", "author_id": 60374, "author_profile": "https://wordpress.stackexchange.com/users/60374", "pm_score": 2, "selected": true, "text": "<p>You probably mean the Distraction Free Writing mode. Am I right? Then you changed wrong ID, it's <strong>#w...
2014/12/09
[ "https://wordpress.stackexchange.com/questions/170736", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64584/" ]
I'm using wordpress 4 and want the fullscreen page editor to be just as wide as the text of my page. eg 1024px. I tried setting #wp-fullscreen-wrap in my css and the dfw\_width option but they all seem to be ignored.
You probably mean the Distraction Free Writing mode. Am I right? Then you changed wrong ID, it's **#wp-content-editor-container** what you want to edit. But every time you hack WordPress core, a kitten dies. So if you like kittens, here is no-offensive solution for you. Put this code into **functions.php** file in your...
170,748
<p>I have set up a set of radio buttons in the customizer to specify one of several different color schemes (aka style sheets) in my theme. When I select a new color for the theme the preview of the theme does not changes. But in another part of the customizer I have a text box. After selecting a color scheme if I go t...
[ { "answer_id": 172212, "author": "AlanP", "author_id": 17097, "author_profile": "https://wordpress.stackexchange.com/users/17097", "pm_score": 2, "selected": false, "text": "<p>The answer is very simple. Change the transport property to refresh:</p>\n\n<pre><code>$wp_customize-&gt;add_se...
2014/12/09
[ "https://wordpress.stackexchange.com/questions/170748", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/17097/" ]
I have set up a set of radio buttons in the customizer to specify one of several different color schemes (aka style sheets) in my theme. When I select a new color for the theme the preview of the theme does not changes. But in another part of the customizer I have a text box. After selecting a color scheme if I go to t...
The answer is very simple. Change the transport property to refresh: ``` $wp_customize->add_setting('cb_color_scheme', array( 'default' => 'blue', 'type' => 'theme_mod', 'transport' => 'refresh', 'capability' => 'manage_options', 'sanitize_callback' => 'wpforge_sanitize_cs_selection', 'priority' => 4, ...
170,768
<p>I am building a WordPress plugin and am stuck on an unexpected problem where my plugin code is running twice.</p> <p>Please see my plugin code:</p> <pre><code>/* Plugin Name: plugin name Plugin URI: Description: Descript Version: 1.0 Author: Author Author URI: License: GPLv2 or later */ if ( ! defined( 'ABSPATH' ...
[ { "answer_id": 170784, "author": "Otto", "author_id": 2232, "author_profile": "https://wordpress.stackexchange.com/users/2232", "pm_score": 3, "selected": false, "text": "<p>Quite simply, it's loading more than once because you're probably actually making more than one HTTP request to \"...
2014/12/10
[ "https://wordpress.stackexchange.com/questions/170768", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64593/" ]
I am building a WordPress plugin and am stuck on an unexpected problem where my plugin code is running twice. Please see my plugin code: ``` /* Plugin Name: plugin name Plugin URI: Description: Descript Version: 1.0 Author: Author Author URI: License: GPLv2 or later */ if ( ! defined( 'ABSPATH' ) ) { exit; //...
Quite simply, it's loading more than once because you're probably actually making more than one HTTP request to "WordPress". You should not do anything like counting on a plugin load like this, because WordPress can load in many different situations, sometimes more than once for even a single page view. The wp-cron p...
170,771
<p>I have post list page of a category. I want to redirect not logged user to login page before he views the post page. I tried with wp-members plugin, but not. In wp-members plugin, there is a hook to <code>the_content()</code> and it changes the content and does not redirect.</p> <p>How can I solve this problem?</p>...
[ { "answer_id": 170775, "author": "Mayeenul Islam", "author_id": 22728, "author_profile": "https://wordpress.stackexchange.com/users/22728", "pm_score": 0, "selected": false, "text": "<p>In your post list page do something like:</p>\n\n<pre><code>&lt;?php\nif (is_user_logged_in() ) {\n ...
2014/12/10
[ "https://wordpress.stackexchange.com/questions/170771", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64594/" ]
I have post list page of a category. I want to redirect not logged user to login page before he views the post page. I tried with wp-members plugin, but not. In wp-members plugin, there is a hook to `the_content()` and it changes the content and does not redirect. How can I solve this problem?
The determination to redirect needs to be made prior to headers being sent to the browser. Otherwise you risk PHP warnings (i.e. errors) when the page is rendered. **This makes the timing of the use of [`wp_redirect()`](https://developer.wordpress.org/reference/functions/wp_redirect/) incorrect in the other answers.** ...
170,799
<p>in wordpress multisite when we give to site admin the option to add new users, site admin dont have the "checkbox" to add the new user without sending the user email with link activation (see the screenshot)</p> <p><img src="https://i.stack.imgur.com/OWWrA.jpg" alt="enter image description here"></p> <p>how can we...
[ { "answer_id": 170775, "author": "Mayeenul Islam", "author_id": 22728, "author_profile": "https://wordpress.stackexchange.com/users/22728", "pm_score": 0, "selected": false, "text": "<p>In your post list page do something like:</p>\n\n<pre><code>&lt;?php\nif (is_user_logged_in() ) {\n ...
2014/12/10
[ "https://wordpress.stackexchange.com/questions/170799", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/36923/" ]
in wordpress multisite when we give to site admin the option to add new users, site admin dont have the "checkbox" to add the new user without sending the user email with link activation (see the screenshot) ![enter image description here](https://i.stack.imgur.com/OWWrA.jpg) how can we add this option to site admin?
The determination to redirect needs to be made prior to headers being sent to the browser. Otherwise you risk PHP warnings (i.e. errors) when the page is rendered. **This makes the timing of the use of [`wp_redirect()`](https://developer.wordpress.org/reference/functions/wp_redirect/) incorrect in the other answers.** ...
170,809
<p>I have a plugin I have developed for a client which works fun on my server but doesn't work on theirs, they are on godaddy so I am guessing it's an issue with their PHP version?</p> <pre><code>add_filter('template_include', function ( $template ) { if(is_tax('hha_cats')){ $template = dirname( __FILE__ ) . '/temp...
[ { "answer_id": 170775, "author": "Mayeenul Islam", "author_id": 22728, "author_profile": "https://wordpress.stackexchange.com/users/22728", "pm_score": 0, "selected": false, "text": "<p>In your post list page do something like:</p>\n\n<pre><code>&lt;?php\nif (is_user_logged_in() ) {\n ...
2014/12/10
[ "https://wordpress.stackexchange.com/questions/170809", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/33936/" ]
I have a plugin I have developed for a client which works fun on my server but doesn't work on theirs, they are on godaddy so I am guessing it's an issue with their PHP version? ``` add_filter('template_include', function ( $template ) { if(is_tax('hha_cats')){ $template = dirname( __FILE__ ) . '/templates/category...
The determination to redirect needs to be made prior to headers being sent to the browser. Otherwise you risk PHP warnings (i.e. errors) when the page is rendered. **This makes the timing of the use of [`wp_redirect()`](https://developer.wordpress.org/reference/functions/wp_redirect/) incorrect in the other answers.** ...
170,843
<p>I need to get name of current custom taxonomy in archive.php file when page is showing posts belong to the one of custom taxonomy categories. </p> <p>It's easy do it in WP loop but I need get it in front of loop's body.</p> <p>How could I do it?</p>
[ { "answer_id": 170775, "author": "Mayeenul Islam", "author_id": 22728, "author_profile": "https://wordpress.stackexchange.com/users/22728", "pm_score": 0, "selected": false, "text": "<p>In your post list page do something like:</p>\n\n<pre><code>&lt;?php\nif (is_user_logged_in() ) {\n ...
2014/12/10
[ "https://wordpress.stackexchange.com/questions/170843", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64623/" ]
I need to get name of current custom taxonomy in archive.php file when page is showing posts belong to the one of custom taxonomy categories. It's easy do it in WP loop but I need get it in front of loop's body. How could I do it?
The determination to redirect needs to be made prior to headers being sent to the browser. Otherwise you risk PHP warnings (i.e. errors) when the page is rendered. **This makes the timing of the use of [`wp_redirect()`](https://developer.wordpress.org/reference/functions/wp_redirect/) incorrect in the other answers.** ...
170,868
<p>I am now creating a website for my client, this client wants me to make each page of the section of header image able to be easily uploaded by them in wordpress admin panel.</p> <p>This is the code I have in functions.php:</p> <pre><code>add_theme_support( 'custom-header' ); $args = array( 'width' =&gt...
[ { "answer_id": 170870, "author": "Amit Mishra", "author_id": 47962, "author_profile": "https://wordpress.stackexchange.com/users/47962", "pm_score": 0, "selected": false, "text": "<p>I am using this solution</p>\n\n<p>I created a custom field called banner and placed it in header.php fi...
2014/12/10
[ "https://wordpress.stackexchange.com/questions/170868", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/23036/" ]
I am now creating a website for my client, this client wants me to make each page of the section of header image able to be easily uploaded by them in wordpress admin panel. This is the code I have in functions.php: ``` add_theme_support( 'custom-header' ); $args = array( 'width' => 950, 'height' ...
create new file in your theme with name header-custom.php next copy this code into that file ``` class customheaderMetabox { private $screen = array( 'post', 'page', ); private $meta_fields = array( array( 'label' => 'Add Image Header', 'id' => 'addimage...
170,877
<p>I have a blog that shows <code>9</code> blogs posts per page, with each additional page of blog posts automatically added using the <a href="http://infiniteajaxscroll.com/" rel="nofollow">Infinite Ajax Scroll</a> plugin. </p> <p>Every time a blog post is successfully queried the <code>$postCount</code> variable inc...
[ { "answer_id": 170887, "author": "paul", "author_id": 1000, "author_profile": "https://wordpress.stackexchange.com/users/1000", "pm_score": 1, "selected": false, "text": "<p><code>WP_Query</code> has a <code>$post_count</code> variable.\n<a href=\"http://codex.wordpress.org/Class_Referen...
2014/12/10
[ "https://wordpress.stackexchange.com/questions/170877", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/27716/" ]
I have a blog that shows `9` blogs posts per page, with each additional page of blog posts automatically added using the [Infinite Ajax Scroll](http://infiniteajaxscroll.com/) plugin. Every time a blog post is successfully queried the `$postCount` variable increases its count by `1`. ``` [...] <body> <div class...
I was able to keep the `$postCount` variable counting by starting a php session in my functions.php file ``` function init_session() { session_start(); } add_action( 'init', 'init_session', 1 ); ``` ...and setting up my loop like so: ``` [...] <body> <div class="posts"> <?php $postCount = ...
170,882
<p>I'm building an app that I'd like to use WP as a backend for. There are three layers of data that I have to manage:</p> <p>Meeting Type Individual Meeting (Many of these in each Meeting Type) Persons Attending Each Meeting</p> <p>My initial through is to create a Custom Post Type for each Meeting Type (only 4-6), ...
[ { "answer_id": 170887, "author": "paul", "author_id": 1000, "author_profile": "https://wordpress.stackexchange.com/users/1000", "pm_score": 1, "selected": false, "text": "<p><code>WP_Query</code> has a <code>$post_count</code> variable.\n<a href=\"http://codex.wordpress.org/Class_Referen...
2014/12/10
[ "https://wordpress.stackexchange.com/questions/170882", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/47789/" ]
I'm building an app that I'd like to use WP as a backend for. There are three layers of data that I have to manage: Meeting Type Individual Meeting (Many of these in each Meeting Type) Persons Attending Each Meeting My initial through is to create a Custom Post Type for each Meeting Type (only 4-6), and then user pos...
I was able to keep the `$postCount` variable counting by starting a php session in my functions.php file ``` function init_session() { session_start(); } add_action( 'init', 'init_session', 1 ); ``` ...and setting up my loop like so: ``` [...] <body> <div class="posts"> <?php $postCount = ...
170,888
<p>I'm attempting to show _all tags on the editing screen on a custom post type (products). Adapting <a href="http://binfalse.de/2010/08/show-all-tags-in-wp-when-creating-new-post/" rel="nofollow">these instructions</a></p> <p>I've created a simple plugin as follows:</p> <pre><code>add_action( 'wp_ajax_get-tagcloud',...
[ { "answer_id": 170892, "author": "vancoder", "author_id": 26778, "author_profile": "https://wordpress.stackexchange.com/users/26778", "pm_score": 1, "selected": false, "text": "<p>By default, <code>get_terms</code> will only return those tags that have some posts attached to them already...
2014/12/10
[ "https://wordpress.stackexchange.com/questions/170888", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/28213/" ]
I'm attempting to show \_all tags on the editing screen on a custom post type (products). Adapting [these instructions](http://binfalse.de/2010/08/show-all-tags-in-wp-when-creating-new-post/) I've created a simple plugin as follows: ``` add_action( 'wp_ajax_get-tagcloud', 'ajax_tag_cloud_wpse_99497', 1 ); function aj...
I needed something like this for a client site, they wanted to add tags to all their products, but I didn't want them just making up new tags, I wanted to give them a list of tags to start with. vancoder's answer provided the key I needed to get this done: the 'hide\_empty' attribute. What makes the code in the origi...
171,918
<p>When asked to work on an existing WordPress Site, I generally take a copy of the whole site and work on it locally. For quite a few years I have used a script such as the following after importing the database locally.</p> <pre><code>UPDATE wp_options SET option_value = replace(option_value, 'http://clientsite.co.u...
[ { "answer_id": 171921, "author": "Matthew Campbell", "author_id": 44704, "author_profile": "https://wordpress.stackexchange.com/users/44704", "pm_score": 2, "selected": false, "text": "<p>I use this for search and replace on databases - <a href=\"https://interconnectit.com/products/searc...
2014/12/11
[ "https://wordpress.stackexchange.com/questions/171918", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/500/" ]
When asked to work on an existing WordPress Site, I generally take a copy of the whole site and work on it locally. For quite a few years I have used a script such as the following after importing the database locally. ``` UPDATE wp_options SET option_value = replace(option_value, 'http://clientsite.co.uk', 'http://lo...
I use this for search and replace on databases - <https://interconnectit.com/products/search-and-replace-for-wordpress-databases/> Simply move files with FTP, export and import database and then run the script searching for old URL and replacing with the new URL. Then I resave permalinks and I'm done. I've moved WP th...
171,939
<p>I have a magazine front page that updates with every issue, and the front page shows the current issue posts which are stickied. So for example, this month all the posts are in a category titlted 'Issue 01' and next month, I will create 'issue 02' which will replace the 'issue 01' sticky posts on the front page. </p...
[ { "answer_id": 171942, "author": "Pieter Goosen", "author_id": 31545, "author_profile": "https://wordpress.stackexchange.com/users/31545", "pm_score": 3, "selected": true, "text": "<p>Here is an idea. Note, this will only work if all posts are in the desired category and if all posts hav...
2014/12/11
[ "https://wordpress.stackexchange.com/questions/171939", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/62977/" ]
I have a magazine front page that updates with every issue, and the front page shows the current issue posts which are stickied. So for example, this month all the posts are in a category titlted 'Issue 01' and next month, I will create 'issue 02' which will replace the 'issue 01' sticky posts on the front page. I am...
Here is an idea. Note, this will only work if all posts are in the desired category and if all posts have only category The posts are returned in an array which you can access through ``` $currentissue->posts ``` With this in mind, you can get the first post ID as follows ``` $currentissue->posts[0]->ID ``` No...
171,949
<p>I am creating a WordPress custom widget and I created the below one that is working fine when I add it in <code>function.php</code>.</p> <pre><code>&lt;?php /* ------------------------------------------------------------------------- * * Most Commented Post Widget /* ----------------------------------------------...
[ { "answer_id": 171945, "author": "Tom J Nowell", "author_id": 736, "author_profile": "https://wordpress.stackexchange.com/users/736", "pm_score": 0, "selected": false, "text": "<p>You should never modify WordPress Core. The people who recommend you do this are mistaken. The reason for th...
2014/12/11
[ "https://wordpress.stackexchange.com/questions/171949", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/52859/" ]
I am creating a WordPress custom widget and I created the below one that is working fine when I add it in `function.php`. ``` <?php /* ------------------------------------------------------------------------- * * Most Commented Post Widget /* ------------------------------------------------------------------------- ...
You don't need to change the core file. They're classes which means they can be extended. It'll require a bit of leg work but all you need to do is load an instance of the class and then extend/add to it. That's the beauty of OOP.That's if there isn't a hook to modify things with already, which there probably will be.
171,964
<p>I am using _s theme .I have all js files under js folder.My code </p> <pre><code>function _s_scripts() { $js_dir = get_template_directory_uri() . "/js/"; foreach(glob($js_dir.'/*.*') as $file) { $label = str_replace(".", "", $file); wp_enqueue_script($label, $js_dir . $file . '.js', array('jquery'), '1.0.0'); } } a...
[ { "answer_id": 171975, "author": "Brandt Solovij", "author_id": 38927, "author_profile": "https://wordpress.stackexchange.com/users/38927", "pm_score": 1, "selected": false, "text": "<p>i think you're putting too many extra bits on the file and path strings.</p>\n\n<p>try this : </p>\n\n...
2014/12/11
[ "https://wordpress.stackexchange.com/questions/171964", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/48294/" ]
I am using \_s theme .I have all js files under js folder.My code ``` function _s_scripts() { $js_dir = get_template_directory_uri() . "/js/"; foreach(glob($js_dir.'/*.*') as $file) { $label = str_replace(".", "", $file); wp_enqueue_script($label, $js_dir . $file . '.js', array('jquery'), '1.0.0'); } } add_action( 'w...
i think you're putting too many extra bits on the file and path strings. try this : ``` function _s_scripts() { $js_dir = get_template_directory_uri() . "/js/"; foreach(glob($js_dir.'*.*') as $file) { $label = str_replace(".", "", $file); wp_enqueue_script($label, $file , array('jquery'), '1.0.0'); } } add_action( '...
171,971
<p>I'm in the process of adding a jQuery plugin to a site I'm working on. Needless to say it requires loading a custom script; also a custom stylesheet. </p> <p>Starting with the stylesheet I've been attempting to go about it the normal way by utilizing <code>wp_register_style()</code> and <code>wp_enqueue_style()</c...
[ { "answer_id": 171975, "author": "Brandt Solovij", "author_id": 38927, "author_profile": "https://wordpress.stackexchange.com/users/38927", "pm_score": 1, "selected": false, "text": "<p>i think you're putting too many extra bits on the file and path strings.</p>\n\n<p>try this : </p>\n\n...
2014/12/11
[ "https://wordpress.stackexchange.com/questions/171971", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/58480/" ]
I'm in the process of adding a jQuery plugin to a site I'm working on. Needless to say it requires loading a custom script; also a custom stylesheet. Starting with the stylesheet I've been attempting to go about it the normal way by utilizing `wp_register_style()` and `wp_enqueue_style()` like so: ``` if ( ! functio...
i think you're putting too many extra bits on the file and path strings. try this : ``` function _s_scripts() { $js_dir = get_template_directory_uri() . "/js/"; foreach(glob($js_dir.'*.*') as $file) { $label = str_replace(".", "", $file); wp_enqueue_script($label, $file , array('jquery'), '1.0.0'); } } add_action( '...
171,979
<p>On one of my custom templates, I need to do some work with the content before displaying it. Is there a way that I can load this content into a variable rather than just outputting it to the page?</p> <p>This is what I've tried but it only outputs the page content, it doesn't load it into the variable.</p> <pre><c...
[ { "answer_id": 171983, "author": "Milo", "author_id": 4771, "author_profile": "https://wordpress.stackexchange.com/users/4771", "pm_score": 1, "selected": false, "text": "<p>If you want to load a template file, execute the code it contains, and save the results to a variable, you need to...
2014/12/11
[ "https://wordpress.stackexchange.com/questions/171979", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/59966/" ]
On one of my custom templates, I need to do some work with the content before displaying it. Is there a way that I can load this content into a variable rather than just outputting it to the page? This is what I've tried but it only outputs the page content, it doesn't load it into the variable. ``` $content = get_te...
You can always use the output buffering to store the printing contents in a variable. ``` function return_get_template_part($slug, $name=null) { ob_start(); get_template_part($slug, $name); $content = ob_get_contents(); ob_end_clean(); return $content; } $content = return_get_template_part('conte...
172,003
<p>The scenary:</p> <p>I'm working in a review system for WordPress, a game review website. It uses default posts, that when under &quot;review&quot; category, shows the review's meta fields (from ACF plugin). It's pretty usual, no secrets.</p> <p>The difference: using a custom post type, other page will &quot;catch&qu...
[ { "answer_id": 171983, "author": "Milo", "author_id": 4771, "author_profile": "https://wordpress.stackexchange.com/users/4771", "pm_score": 1, "selected": false, "text": "<p>If you want to load a template file, execute the code it contains, and save the results to a variable, you need to...
2014/12/11
[ "https://wordpress.stackexchange.com/questions/172003", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/31885/" ]
The scenary: I'm working in a review system for WordPress, a game review website. It uses default posts, that when under "review" category, shows the review's meta fields (from ACF plugin). It's pretty usual, no secrets. The difference: using a custom post type, other page will "catch" data from reviews and show the ...
You can always use the output buffering to store the printing contents in a variable. ``` function return_get_template_part($slug, $name=null) { ob_start(); get_template_part($slug, $name); $content = ob_get_contents(); ob_end_clean(); return $content; } $content = return_get_template_part('conte...
172,006
<p>I have a custom post type "Services". It has a hierarchal taxonomy of "service-category". Service-category has both parent and child terms. </p> <p>I need to count the number of parent terms in the taxonomy. NOT posts. The # of terms in the taxonomy is being used in my code to layout the page in a recursive lo...
[ { "answer_id": 172008, "author": "edwardr", "author_id": 25724, "author_profile": "https://wordpress.stackexchange.com/users/25724", "pm_score": 1, "selected": false, "text": "<p>Try this. Untested but should work -- get_the_terms returns an array with each term, and then sizeof() counts...
2014/12/11
[ "https://wordpress.stackexchange.com/questions/172006", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/34559/" ]
I have a custom post type "Services". It has a hierarchal taxonomy of "service-category". Service-category has both parent and child terms. I need to count the number of parent terms in the taxonomy. NOT posts. The # of terms in the taxonomy is being used in my code to layout the page in a recursive loop. Everything...
As @shanebp suggests, you could use [`wp_count_terms()`](http://codex.wordpress.org/Function_Reference/wp_count_terms) like this: ``` $numTerms = wp_count_terms( 'service-category', array( 'hide_empty'=> false, 'parent' => 0 ) ); ``` The above will list All top parent terms, empty or not. This function us...
172,019
<p>I want to use custom post type in my custom SQL query, but, when I add the custom post type im my query, I get no results. </p> <p>Where's my probelm ?</p> <p>This is the code I've tried </p> <pre><code>$top5_ov_performance = $wpdb-&gt;get_results("SELECT post_id,meta_value FROM ".$wpdb-&gt;prefix."postmeta WHERE...
[ { "answer_id": 172016, "author": "Brandt Solovij", "author_id": 38927, "author_profile": "https://wordpress.stackexchange.com/users/38927", "pm_score": 1, "selected": false, "text": "<p>I can see both sides of the coin in the situation and they are reasonable.</p>\n\n<p>If you are intere...
2014/12/11
[ "https://wordpress.stackexchange.com/questions/172019", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/50501/" ]
I want to use custom post type in my custom SQL query, but, when I add the custom post type im my query, I get no results. Where's my probelm ? This is the code I've tried ``` $top5_ov_performance = $wpdb->get_results("SELECT post_id,meta_value FROM ".$wpdb->prefix."postmeta WHERE meta_key = 'sd_top5_overclocing' ...
I can see both sides of the coin in the situation and they are reasonable. If you are interested in this feature for this plugin and the plugin otherwise meets your needs, I would say re-write the section of the plugin which handles this evaluation and add in the allowance for an optional argument (boolean in this cas...
172,029
<p>I offered to host my cousin's actor profile website on my web hosting account. He had someone create a wordpress site and store it on my account. It was working fine on PhP 5.2, however my host provider has phased it out. Now that i'm forced to use either PhP 5.3 or PhP 5.4, I get a number of errors. </p> <p>If any...
[ { "answer_id": 172030, "author": "Matthew Campbell", "author_id": 44704, "author_profile": "https://wordpress.stackexchange.com/users/44704", "pm_score": 1, "selected": false, "text": "<p>What version of WordPress? It's late and I'm tired but basically, the code is out of date. The site ...
2014/12/12
[ "https://wordpress.stackexchange.com/questions/172029", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64705/" ]
I offered to host my cousin's actor profile website on my web hosting account. He had someone create a wordpress site and store it on my account. It was working fine on PhP 5.2, however my host provider has phased it out. Now that i'm forced to use either PhP 5.3 or PhP 5.4, I get a number of errors. If anyone knows ...
Your WordPress install is out of date. Upgrading to the latest version ( 4.0.1 at time of writing ) should fix those issues, while fixing hundreds of other bugs and security issues. As a side note, you should always keep both your PHP and WordPress installs at the latest versions. Select PHP 5.4, and move to 5.5 and 5...
172,041
<p>I would like to create a wp_query that would return posts meta inside the <code>posts</code> array.</p> <pre><code>$args = array ( 'post_type' =&gt; 'page', 'meta_key' =&gt; 'someMetaKeyName', ); // The Query $query = new WP_Query( $args ); </code></pre> <p>This returns something like:</p> <p><img src="h...
[ { "answer_id": 172042, "author": "Amit Mishra", "author_id": 47962, "author_profile": "https://wordpress.stackexchange.com/users/47962", "pm_score": -1, "selected": false, "text": "<p>Hey Please try this one I think it work fine.</p>\n\n<pre><code>$args = array(\n 'post_type' ...
2014/12/12
[ "https://wordpress.stackexchange.com/questions/172041", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/62519/" ]
I would like to create a wp\_query that would return posts meta inside the `posts` array. ``` $args = array ( 'post_type' => 'page', 'meta_key' => 'someMetaKeyName', ); // The Query $query = new WP_Query( $args ); ``` This returns something like: ![enter image description here](https://i.stack.imgur.com/El...
By default, [`WP_Query`](http://codex.wordpress.org/Class_Reference/WP_Query) returns the standard [`WP_Post`](http://codex.wordpress.org/Class_Reference/WP_Post) objects for the posts being queried. I believe with some clever rewrite and use of the filters given in `WP_Query` you can add objects to the returned `WP_Po...
172,052
<p>Is there a decent standard WP way of wrapping the 3 standard fields (name, email, website) in a div? I'm using bootstrap and would like them to be in their own row.</p> <p>Example:</p> <pre><code> &lt;?php $fields = array( 'author' =&gt; '&lt;div class="col-md-4 comment-form-author"&gt;'...
[ { "answer_id": 172055, "author": "1Up", "author_id": 57524, "author_profile": "https://wordpress.stackexchange.com/users/57524", "pm_score": 0, "selected": false, "text": "<p>Answering my own question - I'm not 100% sure this is safe, but I'm using supplied before/after actions to put in...
2014/12/12
[ "https://wordpress.stackexchange.com/questions/172052", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/57524/" ]
Is there a decent standard WP way of wrapping the 3 standard fields (name, email, website) in a div? I'm using bootstrap and would like them to be in their own row. Example: ``` <?php $fields = array( 'author' => '<div class="col-md-4 comment-form-author">' . '<inpu...
The hook you're using is correct, however, you don't need to bloat it out so much. This simpler version will do exactly what you're looking for, with much less lines. ``` function wpse172052_comment_form_before_fields() { echo '<div class="row">'; } add_action('comment_form_before_fields', 'wpse172052_comment_form...
172,063
<p>Regardless of it being WooCommerce or WordPress, I want to add a couple articles to specific pages, so they show there instead of the images that are there now. <a href="http://www.wein-partner.at/wp/home/" rel="nofollow">Homepage</a> I know, I'm supposed to use shortcodes for that, but for some reason I can't get i...
[ { "answer_id": 172066, "author": "Karun", "author_id": 63470, "author_profile": "https://wordpress.stackexchange.com/users/63470", "pm_score": -1, "selected": false, "text": "<p>Try this</p>\n\n<pre><code>&lt;?php echo do_shortcode('[display-posts id=\"1305\"]'); ?&gt;\n</code></pre>\n" ...
2014/12/12
[ "https://wordpress.stackexchange.com/questions/172063", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/63130/" ]
Regardless of it being WooCommerce or WordPress, I want to add a couple articles to specific pages, so they show there instead of the images that are there now. [Homepage](http://www.wein-partner.at/wp/home/) I know, I'm supposed to use shortcodes for that, but for some reason I can't get it to work. For example: This ...
If you want to put PHP code in the editor you need a plugin, same goes for display-posts. Display Posts shortcode isn't a built in function. <https://wordpress.org/plugins/display-posts-shortcode/>
172,068
<p>I am getting this error in my server error logs:</p> <pre><code>[Thu Dec 11 10:06:30 2014] [error] [client 11.111.111.111] PHP Warning: Missing argument 1 for __(), called in /var/www/vhosts/mysite.org/public_html/wp-content/themes/mysite_v2.2/functions-cpt-projects.php on line 15 and defined in /var/www/vhosts/my...
[ { "answer_id": 172085, "author": "Karun", "author_id": 63470, "author_profile": "https://wordpress.stackexchange.com/users/63470", "pm_score": 3, "selected": true, "text": "<p>you get this error if you passed empty string or did not pass any argument to the <code>__()</code> function.</p...
2014/12/12
[ "https://wordpress.stackexchange.com/questions/172068", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/26255/" ]
I am getting this error in my server error logs: ``` [Thu Dec 11 10:06:30 2014] [error] [client 11.111.111.111] PHP Warning: Missing argument 1 for __(), called in /var/www/vhosts/mysite.org/public_html/wp-content/themes/mysite_v2.2/functions-cpt-projects.php on line 15 and defined in /var/www/vhosts/mysite.org/publi...
you get this error if you passed empty string or did not pass any argument to the `__()` function. You should check where you've used the `__()` function and check what value is being passed as argument.
172,079
<p>i have one cpt Anime and it has post_type taxonomy with term anime and animation</p> <pre><code>anime(cpt): (site domain)/anime/post title | |-(tax)Anime |-(tax)Animation </code></pre> <p>And my url structure are like: (site domain)/anime/post title but i wanna this kind of urls:</p> <pre><code>ani...
[ { "answer_id": 172082, "author": "Karun", "author_id": 63470, "author_profile": "https://wordpress.stackexchange.com/users/63470", "pm_score": -1, "selected": false, "text": "<p>Please check this plugin\n<a href=\"https://wordpress.org/plugins/rewrite/\" rel=\"nofollow\">https://wordpres...
2014/12/12
[ "https://wordpress.stackexchange.com/questions/172079", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/17639/" ]
i have one cpt Anime and it has post\_type taxonomy with term anime and animation ``` anime(cpt): (site domain)/anime/post title | |-(tax)Anime |-(tax)Animation ``` And my url structure are like: (site domain)/anime/post title but i wanna this kind of urls: ``` anime | |-(tax)Anime: (site d...
after alot of try and error i find my solution: ``` add_filter('post_type_link', 'events_permalink_structure', 10, 4); function events_permalink_structure($post_link, $post, $leavename, $sample){ $types=wp_get_object_terms( $post->ID, 'post_types' ); if (( 'animation' == $types[0]->slug )or ( 'comic' == $types[0]->sl...
172,081
<p>When is code in functions.php executed? Is it during the loop? The following does not work when placed in functions.php (not within a function) :</p> <pre><code>if (is_page( 27 )) { echo 'this is the apply page'; } </code></pre> <p>The codex specifies that <a href="http://codex.wordpress.org/Function_Reference/i...
[ { "answer_id": 172083, "author": "fuxia", "author_id": 73, "author_profile": "https://wordpress.stackexchange.com/users/73", "pm_score": 2, "selected": false, "text": "<p><code>is_page()</code> relies on a complete global <code>$wp_query</code> object. If you call it before the action <c...
2014/12/12
[ "https://wordpress.stackexchange.com/questions/172081", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/500/" ]
When is code in functions.php executed? Is it during the loop? The following does not work when placed in functions.php (not within a function) : ``` if (is_page( 27 )) { echo 'this is the apply page'; } ``` The codex specifies that [is\_page()](http://codex.wordpress.org/Function_Reference/is_page#Notes) cannot r...
`is_page()` relies on a complete global `$wp_query` object. If you call it before the action `template_redirect` has been fired, it might be impossible to get that data. Wait for a proper action. Example: ``` add_filter( 'template_include', function( $template ) { if ( is_page( 27 ) ) echo 'this is the a...
172,097
<p>For our articles on our WordPress site, we would like to display article analytics that are collected weekly for each manuscript. We have these native custom fields for each post:</p> <ul> <li>Article Views</li> <li>PDF Downloads</li> <li>PubMed Central Views</li> <li>Article Citations</li> </ul> <p>That data (which...
[ { "answer_id": 172083, "author": "fuxia", "author_id": 73, "author_profile": "https://wordpress.stackexchange.com/users/73", "pm_score": 2, "selected": false, "text": "<p><code>is_page()</code> relies on a complete global <code>$wp_query</code> object. If you call it before the action <c...
2014/12/12
[ "https://wordpress.stackexchange.com/questions/172097", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/54061/" ]
For our articles on our WordPress site, we would like to display article analytics that are collected weekly for each manuscript. We have these native custom fields for each post: * Article Views * PDF Downloads * PubMed Central Views * Article Citations That data (which is coming from different sources) is being col...
`is_page()` relies on a complete global `$wp_query` object. If you call it before the action `template_redirect` has been fired, it might be impossible to get that data. Wait for a proper action. Example: ``` add_filter( 'template_include', function( $template ) { if ( is_page( 27 ) ) echo 'this is the a...
172,099
<p>HI Is there any hook available that we can add it into functions.php and fire only when "Custom meta fields gets edited" ? I really need this . If anyone with the knowledge , please help me.</p> <p>Till now, I've discovered save_post hook but it only fires when post title field or Description fields gets edited. IN...
[ { "answer_id": 172083, "author": "fuxia", "author_id": 73, "author_profile": "https://wordpress.stackexchange.com/users/73", "pm_score": 2, "selected": false, "text": "<p><code>is_page()</code> relies on a complete global <code>$wp_query</code> object. If you call it before the action <c...
2014/12/12
[ "https://wordpress.stackexchange.com/questions/172099", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/63168/" ]
HI Is there any hook available that we can add it into functions.php and fire only when "Custom meta fields gets edited" ? I really need this . If anyone with the knowledge , please help me. Till now, I've discovered save\_post hook but it only fires when post title field or Description fields gets edited. IN my case ...
`is_page()` relies on a complete global `$wp_query` object. If you call it before the action `template_redirect` has been fired, it might be impossible to get that data. Wait for a proper action. Example: ``` add_filter( 'template_include', function( $template ) { if ( is_page( 27 ) ) echo 'this is the a...
172,109
<p>I'm creating a custom post type like this:</p> <pre><code>function btp_work_register_post_type() { $args = array( 'label' =&gt; __('Works', 'btp_theme'), 'labels' =&gt; array( 'name' =&gt; __( 'Works', 'btp_theme' ), 'singular_name' =&gt; _...
[ { "answer_id": 172116, "author": "iEmanuele", "author_id": 35646, "author_profile": "https://wordpress.stackexchange.com/users/35646", "pm_score": 2, "selected": false, "text": "<p>Your CPT and your CT init seem to be right, but the way you get the taxonomy terms is incomplete.\nIf you l...
2014/12/12
[ "https://wordpress.stackexchange.com/questions/172109", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/22933/" ]
I'm creating a custom post type like this: ``` function btp_work_register_post_type() { $args = array( 'label' => __('Works', 'btp_theme'), 'labels' => array( 'name' => __( 'Works', 'btp_theme' ), 'singular_name' => __( 'Work', 'btp_theme' ), ...
Your CPT and your CT init seem to be right, but the way you get the taxonomy terms is incomplete. If you look in [WordPress Codex](http://codex.wordpress.org/Function_Reference/get_terms), the function get\_terms(); accepts two parameters: * $taxonomies * $args If you want to get only parent terms you have to specifi...
172,115
<p>When uploading a large file via the Media uploader, I get the infamous <a href="https://wordpress.stackexchange.com/questions/59763/how-to-fix-http-error-when-uploading-images">HTTP Error</a> problem. I also have the following in the Chrome console:</p> <pre><code>POST http://www.nameofsite.co/wp-admin/async-upload...
[ { "answer_id": 173273, "author": "vlood", "author_id": 733, "author_profile": "https://wordpress.stackexchange.com/users/733", "pm_score": 4, "selected": true, "text": "<p>It's a bit of a shot in the dark, but would you like to move up your memory limit? My guess is that your uploader fa...
2014/12/12
[ "https://wordpress.stackexchange.com/questions/172115", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/500/" ]
When uploading a large file via the Media uploader, I get the infamous [HTTP Error](https://wordpress.stackexchange.com/questions/59763/how-to-fix-http-error-when-uploading-images) problem. I also have the following in the Chrome console: ``` POST http://www.nameofsite.co/wp-admin/async-upload.php 500 (Internal Server...
It's a bit of a shot in the dark, but would you like to move up your memory limit? My guess is that your uploader fails on uploading big files with more serious plugins on just because they are using some of the memory too. In some cases "Memory exhausted" message does not appear if you don't have the right server sett...
172,119
<p>I am needing to create an archive page custom taxonomy terms that are within a custom post type. It's set up as CPT > Custom Taxonomy > Taxonomy Terms.</p> <p>I have a custom post type called "Projects," and when creating the post, the user is to select a type of project for the listing (i.e. Construction, Mainten...
[ { "answer_id": 172120, "author": "edwardr", "author_id": 25724, "author_profile": "https://wordpress.stackexchange.com/users/25724", "pm_score": 2, "selected": false, "text": "<p>There is an <a href=\"http://codex.wordpress.org/Template_Hierarchy#Custom_Taxonomies_display\" rel=\"nofollo...
2014/12/12
[ "https://wordpress.stackexchange.com/questions/172119", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64730/" ]
I am needing to create an archive page custom taxonomy terms that are within a custom post type. It's set up as CPT > Custom Taxonomy > Taxonomy Terms. I have a custom post type called "Projects," and when creating the post, the user is to select a type of project for the listing (i.e. Construction, Maintenance, etc.)...
There is an [example in the WP Codex](http://codex.wordpress.org/Template_Hierarchy#Custom_Taxonomies_display) which should work for you: Try the following naming convention for your taxonomy term archive template: ``` taxonomy-{taxonomy}-{term}.php ``` So, let's say you have a CPT named "Projects," a taxonomy name...
172,122
<p>Is there a way for me to check if the user has explicitly set an excerpt? I need to call the excerpt only if they've specified something in the excerpt field, and not an automatically shortened version of the content.</p>
[ { "answer_id": 172123, "author": "tfrommen", "author_id": 27722, "author_profile": "https://wordpress.stackexchange.com/users/27722", "pm_score": 4, "selected": true, "text": "<p>Try this:</p>\n\n<pre><code>if ( has_excerpt( $some_post_id ) ) {\n // Do something here?\n} else {\n /...
2014/12/12
[ "https://wordpress.stackexchange.com/questions/172122", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/24566/" ]
Is there a way for me to check if the user has explicitly set an excerpt? I need to call the excerpt only if they've specified something in the excerpt field, and not an automatically shortened version of the content.
Try this: ``` if ( has_excerpt( $some_post_id ) ) { // Do something here? } else { // Or here? } ``` **References:** * [`has_excerpt`](http://codex.wordpress.org/Function_Reference/has_excerpt)
172,125
<p>I have created a custom post type which doesn't use <code>the_content()</code> to display anything in the front-end, just using echo's.</p> <p>The user enters data into a text-area field in the plugin admin back-end, the CPT does some data manipulation and everything is output through a template file using a shortc...
[ { "answer_id": 172123, "author": "tfrommen", "author_id": 27722, "author_profile": "https://wordpress.stackexchange.com/users/27722", "pm_score": 4, "selected": true, "text": "<p>Try this:</p>\n\n<pre><code>if ( has_excerpt( $some_post_id ) ) {\n // Do something here?\n} else {\n /...
2014/12/12
[ "https://wordpress.stackexchange.com/questions/172125", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/51823/" ]
I have created a custom post type which doesn't use `the_content()` to display anything in the front-end, just using echo's. The user enters data into a text-area field in the plugin admin back-end, the CPT does some data manipulation and everything is output through a template file using a shortcode. How can I get s...
Try this: ``` if ( has_excerpt( $some_post_id ) ) { // Do something here? } else { // Or here? } ``` **References:** * [`has_excerpt`](http://codex.wordpress.org/Function_Reference/has_excerpt)
172,140
<p>I would like to know which relationship in the database determines which images are displayed in the media dialog when you select 'images uploaded to post' as the search filter.</p> <p>I thought it would just be the 'post_parent' column in wp_posts providing that the post type is an attachment and the mime_type is ...
[ { "answer_id": 172123, "author": "tfrommen", "author_id": 27722, "author_profile": "https://wordpress.stackexchange.com/users/27722", "pm_score": 4, "selected": true, "text": "<p>Try this:</p>\n\n<pre><code>if ( has_excerpt( $some_post_id ) ) {\n // Do something here?\n} else {\n /...
2014/12/12
[ "https://wordpress.stackexchange.com/questions/172140", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/26400/" ]
I would like to know which relationship in the database determines which images are displayed in the media dialog when you select 'images uploaded to post' as the search filter. I thought it would just be the 'post\_parent' column in wp\_posts providing that the post type is an attachment and the mime\_type is correct...
Try this: ``` if ( has_excerpt( $some_post_id ) ) { // Do something here? } else { // Or here? } ``` **References:** * [`has_excerpt`](http://codex.wordpress.org/Function_Reference/has_excerpt)
172,167
<p>I am trying to separate categories because I am working on a theme that will have many different sections on the front page. It makes sense to use categories for these sections. Right now, I have three sections set up with posts in 3 different categories. I have a blog, about and team category. Each category has spe...
[ { "answer_id": 172123, "author": "tfrommen", "author_id": 27722, "author_profile": "https://wordpress.stackexchange.com/users/27722", "pm_score": 4, "selected": true, "text": "<p>Try this:</p>\n\n<pre><code>if ( has_excerpt( $some_post_id ) ) {\n // Do something here?\n} else {\n /...
2014/12/13
[ "https://wordpress.stackexchange.com/questions/172167", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/14761/" ]
I am trying to separate categories because I am working on a theme that will have many different sections on the front page. It makes sense to use categories for these sections. Right now, I have three sections set up with posts in 3 different categories. I have a blog, about and team category. Each category has specif...
Try this: ``` if ( has_excerpt( $some_post_id ) ) { // Do something here? } else { // Or here? } ``` **References:** * [`has_excerpt`](http://codex.wordpress.org/Function_Reference/has_excerpt)
172,183
<p>I've created a PHP script that works great stand alone.</p> <p>I need to convert this script to a WordPress plugin. I've created a custom table in the WordPress database.</p> <p>When i try to get data back I get the <code>wp-admin</code> main page. All the data needs shown on the <code>wp-admin</code> page.</p> <...
[ { "answer_id": 173258, "author": "Karishma Ramchandani", "author_id": 65254, "author_profile": "https://wordpress.stackexchange.com/users/65254", "pm_score": 0, "selected": false, "text": "<p>Please refer this tutorial which detail steps for how to use ajax. may help you\n<a href=\"http:...
2014/12/13
[ "https://wordpress.stackexchange.com/questions/172183", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/36923/" ]
I've created a PHP script that works great stand alone. I need to convert this script to a WordPress plugin. I've created a custom table in the WordPress database. When i try to get data back I get the `wp-admin` main page. All the data needs shown on the `wp-admin` page. ``` function applyfilter() { var timeper...
You can use like this for send ajax... ``` function my_action_javascript() { ?> <script type="text/javascript"> jQuery(document).ready(function ($) { var data = { 'action': 'my_action', 'whatever': '1' }; $.post(ajaxurl, data, function (...
172,203
<p>This code works but since my php skills are not so good, I'm trying to learn how I can make this cleaner.</p> <p>This uses php_mobile_detect plugin which I've updated with new classes since the plugin author hasn't updated in awhile. It checks for the device, if it's not a phone loads one size image and then if it ...
[ { "answer_id": 172207, "author": "fuxia", "author_id": 73, "author_profile": "https://wordpress.stackexchange.com/users/73", "pm_score": 3, "selected": true, "text": "<p>The problem with your code is that it is hard to read and you don’t see clearly what the real goal is. Always start wi...
2014/12/13
[ "https://wordpress.stackexchange.com/questions/172203", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64742/" ]
This code works but since my php skills are not so good, I'm trying to learn how I can make this cleaner. This uses php\_mobile\_detect plugin which I've updated with new classes since the plugin author hasn't updated in awhile. It checks for the device, if it's not a phone loads one size image and then if it is loads...
The problem with your code is that it is hard to read and you don’t see clearly what the real goal is. Always start with the desired minimal result, then make it more flexible, but keep the logic for that separate. All you need is a `<div class="entry-content">`, maybe with a `style` attribute. So start with that: ``...
172,206
<p>I have 1 Custom Post Type of products as well as two taxonomies of <code>types</code> and <code>countries</code>. I'm displaying my custom post type of products on my <code>taxonomy.php</code> page with paged pagination. </p> <p>I am also using the custom post types and custom fields plugin to help with storing th...
[ { "answer_id": 172210, "author": "Pieter Goosen", "author_id": 31545, "author_profile": "https://wordpress.stackexchange.com/users/31545", "pm_score": 2, "selected": false, "text": "<p>In all honesty, I really think that all your misery is caused by your pagination function as we have br...
2014/12/13
[ "https://wordpress.stackexchange.com/questions/172206", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/63171/" ]
I have 1 Custom Post Type of products as well as two taxonomies of `types` and `countries`. I'm displaying my custom post type of products on my `taxonomy.php` page with paged pagination. I am also using the custom post types and custom fields plugin to help with storing the data for the products such as "Name" and "...
In all honesty, I really think that all your misery is caused by your pagination function as we have briefly discussed a while ago. You do have a couple of issues here that are contributing factor to the problems you are experiencing * Changing the main query for a custom query for what ever reason is almost always ...
172,213
<p>I'm developing a Wordpress theme and I've registered a new menu location (called primary menu) and am using a menu with it. In my menu, I have a page called "tier-2 page" under a page called "tier-1 page".</p> <p>I want to get the ID of the parent page ("tier-1 page") while on the child page ("tier-2 page"). I've...
[ { "answer_id": 172215, "author": "kraftner", "author_id": 47733, "author_profile": "https://wordpress.stackexchange.com/users/47733", "pm_score": 0, "selected": false, "text": "<p>I assume you haven't globalized <code>$post</code> before using it:</p>\n\n<pre><code>global $post\n</code><...
2014/12/13
[ "https://wordpress.stackexchange.com/questions/172213", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64769/" ]
I'm developing a Wordpress theme and I've registered a new menu location (called primary menu) and am using a menu with it. In my menu, I have a page called "tier-2 page" under a page called "tier-1 page". I want to get the ID of the parent page ("tier-1 page") while on the child page ("tier-2 page"). I've tried `$pos...
kraftner is probably right but I recommand you to stop using global $post. I mean it's not bad but there are often issues with this big array that can be modified by almost everything running on the wp install. So to me it's not very safe. I prefer using `get_queried_object()` and it works quite the same way : ``` $...
172,261
<p>Having issues showing posts based on custom post type's custom taxonomy. I can get ALL the posts to show up in the custom post type but not JUST the taxonomy. </p> <p>here is how I registered Post Types</p> <pre><code>function reg_forms() { $labels = array( 'name' =&gt; _x( 'Forms', 'post type...
[ { "answer_id": 172215, "author": "kraftner", "author_id": 47733, "author_profile": "https://wordpress.stackexchange.com/users/47733", "pm_score": 0, "selected": false, "text": "<p>I assume you haven't globalized <code>$post</code> before using it:</p>\n\n<pre><code>global $post\n</code><...
2014/12/14
[ "https://wordpress.stackexchange.com/questions/172261", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/5288/" ]
Having issues showing posts based on custom post type's custom taxonomy. I can get ALL the posts to show up in the custom post type but not JUST the taxonomy. here is how I registered Post Types ``` function reg_forms() { $labels = array( 'name' => _x( 'Forms', 'post type general name' ), 'si...
kraftner is probably right but I recommand you to stop using global $post. I mean it's not bad but there are often issues with this big array that can be modified by almost everything running on the wp install. So to me it's not very safe. I prefer using `get_queried_object()` and it works quite the same way : ``` $...
172,296
<p>I'm looking to use <code>.htaccess</code> to rewrite admin page URLs. I'd like to change it from:</p> <pre><code>http://example.com/wp-admin/admin.php?page=whatever&amp;id=5&amp;var=10 </code></pre> <p>to</p> <pre><code>http://example.com/wp-admin/whatever?id=5&amp;var=10 </code></pre> <p>Right now I have:</p> ...
[ { "answer_id": 177255, "author": "awei", "author_id": 67109, "author_profile": "https://wordpress.stackexchange.com/users/67109", "pm_score": 1, "selected": false, "text": "<p>You can try this (sorry, not previously tested). See comments inline for explanation:</p>\n\n<pre><code>RewriteE...
2014/12/15
[ "https://wordpress.stackexchange.com/questions/172296", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64536/" ]
I'm looking to use `.htaccess` to rewrite admin page URLs. I'd like to change it from: ``` http://example.com/wp-admin/admin.php?page=whatever&id=5&var=10 ``` to ``` http://example.com/wp-admin/whatever?id=5&var=10 ``` Right now I have: ``` RewriteEngine On RewriteRule ^members$ admin.php?page=members& [L,E=CLE...
You can try this (sorry, not previously tested). See comments inline for explanation: ``` RewriteEngine On ## if any string separated by | is matched, it will append to ?page= RewriteRule ^(members|add-members|delete)$ admin.php?page=%1 [L,E=CLEAN_CONTACT_URL:1,QSA] ## If querystring starts with page= and is followe...
172,312
<p>I am trying to load a HTML5 Audio player in a popup but am having no luck. The staging site is <a href="http://website-test-lab.com/sites/fm/" rel="nofollow">here</a></p> <p>The audio player works but not after you click the Listen In Pop Up button/link. Here is my code to call the template file which contains the ...
[ { "answer_id": 177255, "author": "awei", "author_id": 67109, "author_profile": "https://wordpress.stackexchange.com/users/67109", "pm_score": 1, "selected": false, "text": "<p>You can try this (sorry, not previously tested). See comments inline for explanation:</p>\n\n<pre><code>RewriteE...
2014/12/15
[ "https://wordpress.stackexchange.com/questions/172312", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/57571/" ]
I am trying to load a HTML5 Audio player in a popup but am having no luck. The staging site is [here](http://website-test-lab.com/sites/fm/) The audio player works but not after you click the Listen In Pop Up button/link. Here is my code to call the template file which contains the same code as the on page audio secti...
You can try this (sorry, not previously tested). See comments inline for explanation: ``` RewriteEngine On ## if any string separated by | is matched, it will append to ?page= RewriteRule ^(members|add-members|delete)$ admin.php?page=%1 [L,E=CLEAN_CONTACT_URL:1,QSA] ## If querystring starts with page= and is followe...
172,333
<p>I'm stuck for some days with this problem and I don't know what else to do. </p> <p>With <strong><code>%somethingHere%</code></strong> on slug rewrite, pages permalinks are broken (CPT AND CT OK).</p> <p>Without, I don't have my desired Post structure but Pages permalinks are OK.</p> <h3>CPT and CT Creation</h3> ...
[ { "answer_id": 172779, "author": "9ete", "author_id": 36352, "author_profile": "https://wordpress.stackexchange.com/users/36352", "pm_score": 1, "selected": false, "text": "<p>Can you provide a link to your site and a little more explanation on what you are trying to achieve?</p>\n\n<p>H...
2014/12/15
[ "https://wordpress.stackexchange.com/questions/172333", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64824/" ]
I'm stuck for some days with this problem and I don't know what else to do. With **`%somethingHere%`** on slug rewrite, pages permalinks are broken (CPT AND CT OK). Without, I don't have my desired Post structure but Pages permalinks are OK. ### CPT and CT Creation ```php function custom_post_type() { register_ta...
Can you provide a link to your site and a little more explanation on what you are trying to achieve? Here's a shot in the dark guess. Archives shows content of type 'post', but you can alter it to include custom post types. Add this filter to your functions.php file: ``` function namespace_add_custom_types( $query )...
172,335
<p>I created a function to display a search box and named it <code>my_get_search_form()</code>. That is a copy of original <code>get_search_form()</code> function. </p> <p>When I call the function, the output is this: <code>Search in http://localhost/wp_ex_3/ &lt;AN EMPTY BOX&gt; &lt;A BROKEN IMAGE LINK&gt;</code>.</p...
[ { "answer_id": 172846, "author": "propz", "author_id": 64941, "author_profile": "https://wordpress.stackexchange.com/users/64941", "pm_score": 1, "selected": false, "text": "<p>you don't need to add another function to get the search form. If you want to change the look of the search for...
2014/12/15
[ "https://wordpress.stackexchange.com/questions/172335", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64826/" ]
I created a function to display a search box and named it `my_get_search_form()`. That is a copy of original `get_search_form()` function. When I call the function, the output is this: `Search in http://localhost/wp_ex_3/ <AN EMPTY BOX> <A BROKEN IMAGE LINK>`. How can I change this ugly display and to not show `http...
you don't need to add another function to get the search form. If you want to change the look of the search form or add another items you'll have to add the `searchform.php` to your theme. It could look like this: ``` <form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>"> ...
172,337
<p>Need to do a check if post has attachments that are not images. I haven't seen this anywhere - thoughts?</p>
[ { "answer_id": 172339, "author": "Mayeenul Islam", "author_id": 22728, "author_profile": "https://wordpress.stackexchange.com/users/22728", "pm_score": 3, "selected": false, "text": "<p>You can use the following within a loop:</p>\n\n<pre><code>$files = get_attached_media( $type, $post_i...
2014/12/15
[ "https://wordpress.stackexchange.com/questions/172337", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/4902/" ]
Need to do a check if post has attachments that are not images. I haven't seen this anywhere - thoughts?
Here's how to check if the post has an attachment other than image (or other mime types): ``` <?php $attachments = get_posts( array( 'post_type' => 'attachment', 'posts_per_page' => -1, 'post_parent' => $post->ID, 'exclude' => 'image' )); if ( $attachments )...
172,349
<p>What I want to do is assign a hierarchical term to a custom post type:</p> <pre><code>function create_frontles_posts() { $x = 1; do { $post_id = wp_insert_post(array( 'comment_status' =&gt; 'closed', 'ping_status' =&gt; 'closed', 'post_author' =&gt; 1, 'post_name' ...
[ { "answer_id": 172421, "author": "Karun", "author_id": 63470, "author_profile": "https://wordpress.stackexchange.com/users/63470", "pm_score": 1, "selected": false, "text": "<p>Here is an example. I've tried to explain each process happening in each line. I hope this code can easily expl...
2014/12/15
[ "https://wordpress.stackexchange.com/questions/172349", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60702/" ]
What I want to do is assign a hierarchical term to a custom post type: ``` function create_frontles_posts() { $x = 1; do { $post_id = wp_insert_post(array( 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => 1, 'post_name' => 'Tile'.$x, ...
I find out the problem and the solution. I debugged the "wp\_set\_object\_terms" by using "is\_wp\_error" and I got "Invalid Taxonomy" message, then I realized that when the posts was being created that term didn't exists. So I change the hook to "init" in the programmatically\_create\_post() function, and voila! Belo...
172,365
<p>I'm trying to password protect content in a custom page template, however when i enter the password i assigned in the backend, it doesn't authenticate, instead just reloads the page upon submission. I know the code below isn't great, but please try to disregard this - I just need help getting the password authentica...
[ { "answer_id": 172421, "author": "Karun", "author_id": 63470, "author_profile": "https://wordpress.stackexchange.com/users/63470", "pm_score": 1, "selected": false, "text": "<p>Here is an example. I've tried to explain each process happening in each line. I hope this code can easily expl...
2014/12/15
[ "https://wordpress.stackexchange.com/questions/172365", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/26686/" ]
I'm trying to password protect content in a custom page template, however when i enter the password i assigned in the backend, it doesn't authenticate, instead just reloads the page upon submission. I know the code below isn't great, but please try to disregard this - I just need help getting the password authenticatio...
I find out the problem and the solution. I debugged the "wp\_set\_object\_terms" by using "is\_wp\_error" and I got "Invalid Taxonomy" message, then I realized that when the posts was being created that term didn't exists. So I change the hook to "init" in the programmatically\_create\_post() function, and voila! Belo...
172,370
<p>I have a large number of posts that each represent a very specific type of data. Each post title is the SKU for the data &amp; information. Folks have become pretty savvy on the URL structure and their shortcuts (redirects) are causing them to get incorrect data. Using the wrong data is NOT a good thing in this case...
[ { "answer_id": 172421, "author": "Karun", "author_id": 63470, "author_profile": "https://wordpress.stackexchange.com/users/63470", "pm_score": 1, "selected": false, "text": "<p>Here is an example. I've tried to explain each process happening in each line. I hope this code can easily expl...
2014/12/15
[ "https://wordpress.stackexchange.com/questions/172370", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64488/" ]
I have a large number of posts that each represent a very specific type of data. Each post title is the SKU for the data & information. Folks have become pretty savvy on the URL structure and their shortcuts (redirects) are causing them to get incorrect data. Using the wrong data is NOT a good thing in this case. **Fo...
I find out the problem and the solution. I debugged the "wp\_set\_object\_terms" by using "is\_wp\_error" and I got "Invalid Taxonomy" message, then I realized that when the posts was being created that term didn't exists. So I change the hook to "init" in the programmatically\_create\_post() function, and voila! Belo...
172,383
<p>I have got an attachment id, but I need an url. How can I get an url from the attachment object?</p> <pre><code>// When an image is selected, run a callback. frame.on( 'select', function() { // Grab the selected attachment. var attachment = frame.state().get('selection').first(); $('#' + id).val(attachm...
[ { "answer_id": 172384, "author": "Robert hue", "author_id": 22461, "author_profile": "https://wordpress.stackexchange.com/users/22461", "pm_score": 2, "selected": false, "text": "<p>If you have attachment id then you can call <code>wp_get_attachment_url</code> function to get URL of atta...
2014/12/16
[ "https://wordpress.stackexchange.com/questions/172383", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/59428/" ]
I have got an attachment id, but I need an url. How can I get an url from the attachment object? ``` // When an image is selected, run a callback. frame.on( 'select', function() { // Grab the selected attachment. var attachment = frame.state().get('selection').first(); $('#' + id).val(attachment.id); }); ...
You have to convert attachment variable to JSON object using toJSON() . Then you can its property. use ``` attachment = frame.state().get('selection').first().toJSON(); ``` instead of ``` attachment = frame.state().get('selection').first(); ```
172,410
<p>Currently I'm trying to create a large header (jumbotron) on my website. The large header is loaded as inline css with the following code:</p> <pre><code>&lt;div class="fill" style="background-image:url('&lt;?php echo img url ?&gt;')"&gt;&lt;/div&gt; </code></pre> <p>I'm using the <a href="https://github.com/vocec...
[ { "answer_id": 172384, "author": "Robert hue", "author_id": 22461, "author_profile": "https://wordpress.stackexchange.com/users/22461", "pm_score": 2, "selected": false, "text": "<p>If you have attachment id then you can call <code>wp_get_attachment_url</code> function to get URL of atta...
2014/12/16
[ "https://wordpress.stackexchange.com/questions/172410", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/20548/" ]
Currently I'm trying to create a large header (jumbotron) on my website. The large header is loaded as inline css with the following code: ``` <div class="fill" style="background-image:url('<?php echo img url ?>')"></div> ``` I'm using the [Multi-post-thumbnails](https://github.com/voceconnect/multi-post-thumbnails/...
You have to convert attachment variable to JSON object using toJSON() . Then you can its property. use ``` attachment = frame.state().get('selection').first().toJSON(); ``` instead of ``` attachment = frame.state().get('selection').first(); ```
172,422
<p>Is it possible to get this function paged? I've tried to add previous and next links but i'ts not working... </p> <pre><code>function get_related_author_posts() { global $authordata, $post; $authors_posts = get_posts( array( 'author' =&gt; $authordata-&gt;ID, 'post_type' =&gt; 'kenniscentru...
[ { "answer_id": 172429, "author": "Karun", "author_id": 63470, "author_profile": "https://wordpress.stackexchange.com/users/63470", "pm_score": 0, "selected": false, "text": "<p>In your code after <code>global $authordata, $post;</code> add</p>\n\n<pre><code>$paged = (get_query_var('paged...
2014/12/16
[ "https://wordpress.stackexchange.com/questions/172422", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18693/" ]
Is it possible to get this function paged? I've tried to add previous and next links but i'ts not working... ``` function get_related_author_posts() { global $authordata, $post; $authors_posts = get_posts( array( 'author' => $authordata->ID, 'post_type' => 'kenniscentrum', 'post__not_in' => a...
Instead of a function to place on functions.php, I find a workaround that can be placed on a template file: ``` <?php global $authordata, $post; query_posts( array( 'author' => $authordata->ID, 'post_type' => 'post', 'post__not_in' => array( $post->ID ), 'paged' => $paged, 'posts_per_page' => 5 )); if (...
172,425
<p>In a post I want to always show one of two options- </p> <p>If the post has nothing but a thumbnail image show the thumbnail. </p> <p>If the post has <strong>both</strong> the thumbnail and a gallery then show the only gallery and don't show the thumbnail. </p> <p>I am using a plugin for the gallery called <a hre...
[ { "answer_id": 172427, "author": "Karun", "author_id": 63470, "author_profile": "https://wordpress.stackexchange.com/users/63470", "pm_score": 0, "selected": false, "text": "<p>You can do preg_match to check if the content contains gallery shortcode</p>\n\n<pre><code> &lt;?php \n ...
2014/12/16
[ "https://wordpress.stackexchange.com/questions/172425", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/6787/" ]
In a post I want to always show one of two options- If the post has nothing but a thumbnail image show the thumbnail. If the post has **both** the thumbnail and a gallery then show the only gallery and don't show the thumbnail. I am using a plugin for the gallery called [metaslider](https://wordpress.org/plugins/...
Just use the public API functions: [`has_shortcode( $content, $tag );`](https://github.com/WordPress/WordPress/blob/4.0/wp-includes/shortcodes.php#L157-L176). It uses [`shortcode_exists( $shortcode );`](https://github.com/WordPress/WordPress/blob/4.0/wp-includes/shortcodes.php#L143) internally to search the `global $sh...