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
190,923
<p>I have a nav menu with a depth of 2.</p> <pre><code>wp_nav_menu( array( 'theme_location' =&gt; 'primary_navigation', 'depth' =&gt; 2 ) ); </code></pre> <p>When I am active on a page in the nav menu that has no children, that <code>li</code> menu item has <code>active</code> appended. H...
[ { "answer_id": 190926, "author": "Hemant Aggarwal", "author_id": 63853, "author_profile": "https://wordpress.stackexchange.com/users/63853", "pm_score": 1, "selected": false, "text": "<p>Can you add the complete output code for the navigation menu. The code you pasted seems to be a strip...
2015/06/09
[ "https://wordpress.stackexchange.com/questions/190923", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/51823/" ]
I have a nav menu with a depth of 2. ``` wp_nav_menu( array( 'theme_location' => 'primary_navigation', 'depth' => 2 ) ); ``` When I am active on a page in the nav menu that has no children, that `li` menu item has `active` appended. However, when the menu item has children, `has-children...
Can you add the complete output code for the navigation menu. The code you pasted seems to be a stripped version. Moreover, WordPress adds 'current\_page\_item' class to the list item if it is currently being viewed. For more info, check this [WordPress documentation](https://codex.wordpress.org/Function_Reference/wp_...
190,940
<p>I am currently working on a theme for a client and now just got into a problem: When I want to set an image (also existing/already uploaded images don't work) the editor just not accept it and don't set it as the post thumbnail for the post.</p> <p>Any help would be appreciated.</p> <p>EDIT: Here is an screenshot ...
[ { "answer_id": 190941, "author": "TalwinderSingh", "author_id": 74421, "author_profile": "https://wordpress.stackexchange.com/users/74421", "pm_score": -1, "selected": false, "text": "<p>You need to add support for thumbnails in your theme. So, put this in your theme files:</p>\n\n<p><co...
2015/06/09
[ "https://wordpress.stackexchange.com/questions/190940", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/71075/" ]
I am currently working on a theme for a client and now just got into a problem: When I want to set an image (also existing/already uploaded images don't work) the editor just not accept it and don't set it as the post thumbnail for the post. Any help would be appreciated. EDIT: Here is an screenshot for the case that...
I figured out it was because of an script that was delivered with the **Options Framework**. There was a little piece of code in my `functions.php` which caused wrong javascript to be loaded. When you are having the same problem, be sure to search for something like `wp_enqueue_media();` or something of the following ...
190,951
<p>I'm quite new to WP theme development so I'm sorry if the answer for this question may seem obvious. </p> <p>I'm developing a custom WordPress theme from scratch, and I'm stuck working on the menus. My header menu has some submenus that I'd like to style, but when I call the menu with the wp_nav_menu() function, th...
[ { "answer_id": 190941, "author": "TalwinderSingh", "author_id": 74421, "author_profile": "https://wordpress.stackexchange.com/users/74421", "pm_score": -1, "selected": false, "text": "<p>You need to add support for thumbnails in your theme. So, put this in your theme files:</p>\n\n<p><co...
2015/06/09
[ "https://wordpress.stackexchange.com/questions/190951", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74422/" ]
I'm quite new to WP theme development so I'm sorry if the answer for this question may seem obvious. I'm developing a custom WordPress theme from scratch, and I'm stuck working on the menus. My header menu has some submenus that I'd like to style, but when I call the menu with the wp\_nav\_menu() function, the HTML o...
I figured out it was because of an script that was delivered with the **Options Framework**. There was a little piece of code in my `functions.php` which caused wrong javascript to be loaded. When you are having the same problem, be sure to search for something like `wp_enqueue_media();` or something of the following ...
190,967
<p>I use a random wp_query to load 3 posts from over 600 posts in total with this query.</p> <pre><code> &lt;?php $args = array( 'post_type' =&gt; 'post', 'cat' =&gt; 1, 'orderby' =&gt; 'rand', 'posts_per_page' =&gt; 3 ); ...
[ { "answer_id": 190968, "author": "s_ha_dum", "author_id": 21376, "author_profile": "https://wordpress.stackexchange.com/users/21376", "pm_score": 0, "selected": false, "text": "<p>You aren't really talking about forcing WordPress to be more random; you are talking about forcing the datab...
2015/06/09
[ "https://wordpress.stackexchange.com/questions/190967", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/9442/" ]
I use a random wp\_query to load 3 posts from over 600 posts in total with this query. ``` <?php $args = array( 'post_type' => 'post', 'cat' => 1, 'orderby' => 'rand', 'posts_per_page' => 3 ); $all_posts = new W...
I wanted to point out that sometimes in the case of random it's not the code at all, if you're using a host that does auto cache or are using a cache plugin, it's possible the page or the query itself is getting cached and therefor the same results will show. Fixes for this issue would be to have the host or the plugi...
190,973
<p>I am trying to set up a <code>wp-cli.yml</code> file but every time I run the command, the file is ignored.</p> <p>Where should the file be located? And how should I call the command to use it?</p> <p>I tried having a file in the project's root directory, as well as a folder above. I have also tried using the foll...
[ { "answer_id": 190975, "author": "Welcher", "author_id": 27210, "author_profile": "https://wordpress.stackexchange.com/users/27210", "pm_score": 2, "selected": false, "text": "<p>According to the <a href=\"https://make.wordpress.org/cli/handbook/config/\" rel=\"nofollow noreferrer\">docs...
2015/06/09
[ "https://wordpress.stackexchange.com/questions/190973", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/30984/" ]
I am trying to set up a `wp-cli.yml` file but every time I run the command, the file is ignored. Where should the file be located? And how should I call the command to use it? I tried having a file in the project's root directory, as well as a folder above. I have also tried using the following file names: `wp-cli.l...
**TL;DR**: 1. Run `wp --version --debug` 2. Check that `wp-cli.yml` was found 3. Check that the `ABSPATH` set by WP-CLI matches the directory where WP is installed 4. Look at `find_wp_root()` for hints about why it's finding the wrong folder --- The docs say: > > inside the current working directory **(or upwards)...
190,993
<p>My ajax call for json data works ok like this functions.php:</p> <pre><code>add_action( 'wp_ajax_nopriv_load-filter', 'prefix_load_cat_posts' ); add_action( 'wp_ajax_load-filter', 'prefix_load_cat_posts' ); function prefix_load_cat_posts () { //get data here } </code></pre> <p>javascript:</p> <pre><code>var aja...
[ { "answer_id": 191029, "author": "sohan", "author_id": 69017, "author_profile": "https://wordpress.stackexchange.com/users/69017", "pm_score": 3, "selected": false, "text": "<p><code>admin-ajax.php</code> is part of the WordPress <a href=\"http://codex.wordpress.org/AJAX_in_Plugins\" rel...
2015/06/09
[ "https://wordpress.stackexchange.com/questions/190993", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/58117/" ]
My ajax call for json data works ok like this functions.php: ``` add_action( 'wp_ajax_nopriv_load-filter', 'prefix_load_cat_posts' ); add_action( 'wp_ajax_load-filter', 'prefix_load_cat_posts' ); function prefix_load_cat_posts () { //get data here } ``` javascript: ``` var ajaxurl = 'http://'+window.location.host...
> > 1) Why use `admin-ajax.php` instead of encoding your json in a separate > file like `themes/example/json.php` and encode your data there? > > > Using `admin-ajax.php` means that the WordPress Core is loaded and available. WIthout that, you would need to hand load the files you need, which is a complicated pro...
190,999
<p>I'd like to auto-generate images, or rather image sizes, in old posts where the size is currently missing.</p> <p>Specifically I'm hoping to generate sizes on the fly when a specific (old) image size is missing, but the original image is still in tact.</p> <p><strong>Background:</strong> A while back I cleaned hou...
[ { "answer_id": 191000, "author": "Welcher", "author_id": 27210, "author_profile": "https://wordpress.stackexchange.com/users/27210", "pm_score": 1, "selected": false, "text": "<p>If you have access to install, or if it is available on your server I would recommend using <a href=\"http://...
2015/06/10
[ "https://wordpress.stackexchange.com/questions/190999", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/28821/" ]
I'd like to auto-generate images, or rather image sizes, in old posts where the size is currently missing. Specifically I'm hoping to generate sizes on the fly when a specific (old) image size is missing, but the original image is still in tact. **Background:** A while back I cleaned house with images on a site in ho...
If you have access to install, or if it is available on your server I would recommend using [WP-CLI](http://wp-cli.org/). It has a command to regenerate the media: ``` wp media regenerate ``` If not, you can try a plugin such as [Regenerate Thumbnails](https://wordpress.org/plugins/regenerate-thumbnails/) Good luck...
191,002
<p>I am attempting to create a file using <code>fopen()</code> on <code>save_post</code>. I am having trouble finding the right condtionals to prevent the the file from being created from an auto save. I only want to create the file when I click publish the post. Currently the file is created when I click "add new" and...
[ { "answer_id": 191008, "author": "josh", "author_id": 24323, "author_profile": "https://wordpress.stackexchange.com/users/24323", "pm_score": 2, "selected": false, "text": "<p>If you are using the <a href=\"https://codex.wordpress.org/Plugin_API/Action_Reference/save_post\" rel=\"nofollo...
2015/06/10
[ "https://wordpress.stackexchange.com/questions/191002", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/35351/" ]
I am attempting to create a file using `fopen()` on `save_post`. I am having trouble finding the right condtionals to prevent the the file from being created from an auto save. I only want to create the file when I click publish the post. Currently the file is created when I click "add new" and when I fill in the title...
If you are using the [save\_post](https://codex.wordpress.org/Plugin_API/Action_Reference/save_post) action hook; then you can prevent the code from executing during an autosave with the following conditional: ``` function do_not_autosave( $post ) { // Check to see if we are autosaving if (defined('DOING_AUTO...
191,003
<p>I use a plugin that creates a custom post type with a slug that I am wanting to change. I don't want to overwrite the plugin files, so I'm wondering how I can change the slug using a separate function? Thanks.</p> <pre><code>// Register post type add_action( 'init', 'ctc_register_post_type_item' ); function ctc_reg...
[ { "answer_id": 191014, "author": "Evan Yeung", "author_id": 1878, "author_profile": "https://wordpress.stackexchange.com/users/1878", "pm_score": 0, "selected": false, "text": "<p>Take a look at <a href=\"https://wordpress.stackexchange.com/a/42164/1878\">Tom's answer</a> on a similar qu...
2015/06/10
[ "https://wordpress.stackexchange.com/questions/191003", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74448/" ]
I use a plugin that creates a custom post type with a slug that I am wanting to change. I don't want to overwrite the plugin files, so I'm wondering how I can change the slug using a separate function? Thanks. ``` // Register post type add_action( 'init', 'ctc_register_post_type_item' ); function ctc_register_post_typ...
In the code you posted, the filter `ctc_post_type_item_args` gets applied to the `$args` array before it is passed into `register_post_type()`. Putting a function into your themes `functions.php` and hooking it to the filter should do the trick: ``` function wpse_191003_ctc_post_type_item_args( $args ) { $args['r...
191,035
<p>I would like to password protect a page on my blog. Wordpress allows me to give one single password to each protected page. Is there a way to create more than one valid password to access that page?</p>
[ { "answer_id": 191014, "author": "Evan Yeung", "author_id": 1878, "author_profile": "https://wordpress.stackexchange.com/users/1878", "pm_score": 0, "selected": false, "text": "<p>Take a look at <a href=\"https://wordpress.stackexchange.com/a/42164/1878\">Tom's answer</a> on a similar qu...
2015/06/10
[ "https://wordpress.stackexchange.com/questions/191035", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/58599/" ]
I would like to password protect a page on my blog. Wordpress allows me to give one single password to each protected page. Is there a way to create more than one valid password to access that page?
In the code you posted, the filter `ctc_post_type_item_args` gets applied to the `$args` array before it is passed into `register_post_type()`. Putting a function into your themes `functions.php` and hooking it to the filter should do the trick: ``` function wpse_191003_ctc_post_type_item_args( $args ) { $args['r...
191,045
<p>I have created a shortcode that retrives and displays a form.The content of the attribute in HTML. </p> <pre><code>function check_my_login( $atts) { return '&lt;form action="" name="" method="post" enctype="multipart/form-data"&gt; &lt;div class="form-group"&gt; &lt;l...
[ { "answer_id": 191059, "author": "David Labbe", "author_id": 38434, "author_profile": "https://wordpress.stackexchange.com/users/38434", "pm_score": 3, "selected": true, "text": "<p>Use this instead:</p>\n\n<p>Concatenate the html then return it.</p>\n\n<pre><code>function check_my_login...
2015/06/10
[ "https://wordpress.stackexchange.com/questions/191045", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/68882/" ]
I have created a shortcode that retrives and displays a form.The content of the attribute in HTML. ``` function check_my_login( $atts) { return '<form action="" name="" method="post" enctype="multipart/form-data"> <div class="form-group"> <label for="description">Projec...
Use this instead: Concatenate the html then return it. ``` function check_my_login( $atts) { $html = '<form action="" name="" method="post" enctype="multipart/form-data">'; $html .= '<div class="form-group">'; $html .= '<label for="description">Project Description</label>'; $html .= '<textarea name="...
191,061
<p>For my theme development purposes I have a local WordPress installation that I run from a VM, accessed via, let's say, <code>http://local.app</code>. I also have a remote version of the site on a staging server, <code>http://staging.example.com</code>. </p> <p>The staging site contains all the content that I design...
[ { "answer_id": 238412, "author": "Kat", "author_id": 58601, "author_profile": "https://wordpress.stackexchange.com/users/58601", "pm_score": 2, "selected": false, "text": "<p>Somewhere in the core, URLs get absolutely pathed when put into the database. </p>\n\n<p>Why don't you just load ...
2015/06/10
[ "https://wordpress.stackexchange.com/questions/191061", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/23620/" ]
For my theme development purposes I have a local WordPress installation that I run from a VM, accessed via, let's say, `http://local.app`. I also have a remote version of the site on a staging server, `http://staging.example.com`. The staging site contains all the content that I design the theme around (i.e posts, pa...
Somewhere in the core, URLs get absolutely pathed when put into the database. Why don't you just load all your images from your staging server? Have the staging server hold the files while your local mirrors it. Add the following to your `.htaccess` to your local uploads folder and the contents are as follows: ``` #...
191,081
<p>If a logged-out user visits a page, and then revisit it when logged-in, it will show the cached version. There's a <a href="https://wordpress.stackexchange.com/questions/112640/how-to-force-content-refresh-of-a-page-that-has-been-loaded-previously-by-the-us">closed question</a> similar to this with an answer that su...
[ { "answer_id": 192546, "author": "E. Serrano", "author_id": 41259, "author_profile": "https://wordpress.stackexchange.com/users/41259", "pm_score": 2, "selected": false, "text": "<p>Since you already have the \"Don't cache pages for logged in users\" option activated, what about selectin...
2015/06/10
[ "https://wordpress.stackexchange.com/questions/191081", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/24875/" ]
If a logged-out user visits a page, and then revisit it when logged-in, it will show the cached version. There's a [closed question](https://wordpress.stackexchange.com/questions/112640/how-to-force-content-refresh-of-a-page-that-has-been-loaded-previously-by-the-us) similar to this with an answer that suggests to set ...
Since you already have the "Don't cache pages for logged in users" option activated, what about selecting `cache with validation` under `Cache Control Policy` for "HTML" content? Explanation: Essentially, the "don't cache pages for logged in users" option should already be sending a `no-cache` header for your logged u...
191,083
<p>The <a href="https://codex.wordpress.org/Function_Reference/get_post_meta" rel="nofollow">documentation</a> from <code>get_post_meta</code> makes it sound as if the <code>single</code> argument will determine whether or not meta values are returned in an array or not. For example:</p> <pre><code>// If I set single ...
[ { "answer_id": 191086, "author": "s_ha_dum", "author_id": 21376, "author_profile": "https://wordpress.stackexchange.com/users/21376", "pm_score": 3, "selected": true, "text": "<blockquote>\n <p>This works fine if I'm only returning data for a single meta key...but\n fails if I want to ...
2015/06/10
[ "https://wordpress.stackexchange.com/questions/191083", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/48162/" ]
The [documentation](https://codex.wordpress.org/Function_Reference/get_post_meta) from `get_post_meta` makes it sound as if the `single` argument will determine whether or not meta values are returned in an array or not. For example: ``` // If I set single to false, or leave it blank it's returned as an array [my-meta...
> > This works fine if I'm only returning data for a single meta key...but > fails if I want to return all of the meta data, but return them all as > strings (single). > > > This doesn't make a lot of sense. A function in PHP can only return a single value so there is no way to return *all* meta as *strings* (pl...
191,101
<p>I'm looking for a way to move the "Visit Site" link from drop-down and add it to the main toolbar, just like in the image shown below:</p> <p><a href="https://i.stack.imgur.com/04mLP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/04mLP.png" alt="enter image description here"></a></p>
[ { "answer_id": 191108, "author": "Rarst", "author_id": 847, "author_profile": "https://wordpress.stackexchange.com/users/847", "pm_score": 4, "selected": true, "text": "<p>Not complicated, but a little tricky to get timing right.</p>\n\n<p>Something like this should work, but you might n...
2015/06/10
[ "https://wordpress.stackexchange.com/questions/191101", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74500/" ]
I'm looking for a way to move the "Visit Site" link from drop-down and add it to the main toolbar, just like in the image shown below: [![enter image description here](https://i.stack.imgur.com/04mLP.png)](https://i.stack.imgur.com/04mLP.png)
Not complicated, but a little tricky to get timing right. Something like this should work, but you might need to experiment with priority to get the link to specific position on the bar: ``` add_action( 'admin_bar_menu', function ( $wp_admin_bar ) { if ( ! is_admin() ) { return; } /** @var WP_Ad...
191,126
<p>The code on the page looks like this:</p> <pre><code>if ( ! empty( $image ) ) : ?&gt; &lt;div class="headshot"&gt; &lt;img src="&lt;?php echo esc_url( $image ); ?&gt;" alt="Photo of &lt;?php echo esc_attr( $author_name ); ?&gt;"/&gt; &lt;/div&gt; </code></pre> <p>But when the image shows up on the page it's ...
[ { "answer_id": 191130, "author": "Serpentsoft", "author_id": 74048, "author_profile": "https://wordpress.stackexchange.com/users/74048", "pm_score": 2, "selected": false, "text": "<p>esc_url never force the URL to protocol it's only checking and escaping the passed URL from invalid chara...
2015/06/10
[ "https://wordpress.stackexchange.com/questions/191126", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/70686/" ]
The code on the page looks like this: ``` if ( ! empty( $image ) ) : ?> <div class="headshot"> <img src="<?php echo esc_url( $image ); ?>" alt="Photo of <?php echo esc_attr( $author_name ); ?>"/> </div> ``` But when the image shows up on the page it's using http instead of https like the rest of the site. When ...
esc\_url never force the URL to protocol it's only checking and escaping the passed URL from invalid characters, the $protocols variable is an array of acceptable (white list) protocols not for forcing destination URL. ``` // Forcing URL to https instead of http $YOUR_URL = esc_url($YOUR_URL); if( 'http' == parse_ur...
191,138
<p>I'm using wp_query to get all attachments, and it works, but I wonder how could I get attachments in full size because this query returns images in medium.</p> <pre><code>&lt;?php $args = array('post_status' =&gt; 'inherit', 'post_type' =&gt; 'attachment', 'posts_per_page' =&gt; 5 ); $wp_query = new WP_Que...
[ { "answer_id": 191140, "author": "iridian", "author_id": 43066, "author_profile": "https://wordpress.stackexchange.com/users/43066", "pm_score": 0, "selected": false, "text": "<p>You should be able to set your own image tag. You can replace the_content(); with this.</p>\n\n<pre><code>&lt...
2015/06/10
[ "https://wordpress.stackexchange.com/questions/191138", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/70495/" ]
I'm using wp\_query to get all attachments, and it works, but I wonder how could I get attachments in full size because this query returns images in medium. ``` <?php $args = array('post_status' => 'inherit', 'post_type' => 'attachment', 'posts_per_page' => 5 ); $wp_query = new WP_Query($args); while (hav...
If you look at the raw post data... ``` while (have_posts() ) { the_post(); ?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>><?php var_dump($post); ?> </article><?php } ``` You will see that there is nothing in there to specify "medium", so I went looking. [There is a filter on `the_cont...
191,139
<p>I'm trying to add a new rewrite rule but it doesn't seem to be getting added to the array and it certainly isn't working.</p> <p>I'm trying to get this URL, <code>dult.dev/lists/games/destiny</code>, to take me from a list view of <code>/lists/games/</code> (which works just fine) to a single post view of that part...
[ { "answer_id": 191141, "author": "David Labbe", "author_id": 38434, "author_profile": "https://wordpress.stackexchange.com/users/38434", "pm_score": 2, "selected": false, "text": "<p>Try this. You also don't want to include $wp_rewrite->flush_rules() inside your function as that would fl...
2015/06/11
[ "https://wordpress.stackexchange.com/questions/191139", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74511/" ]
I'm trying to add a new rewrite rule but it doesn't seem to be getting added to the array and it certainly isn't working. I'm trying to get this URL, `dult.dev/lists/games/destiny`, to take me from a list view of `/lists/games/` (which works just fine) to a single post view of that particular post. My rewrite rule isn...
Try this. You also don't want to include $wp\_rewrite->flush\_rules() inside your function as that would flush on every page load. ``` add_action('rewrite_rules_array', 'new_rewrite_rules'); function new_rewrite_rules($rules){ $newrules = array(); $newrules[ '^lists/([^/]*)/([^/]*)/?' = 'index.php?lis...
191,160
<p>Because of the lack of documentation about <a href="https://codex.wordpress.org/Plugin_API/Filter_Reference/post_limits" rel="nofollow"><code>post_limits</code></a>, its hard to learn more about this function and when to use it. Never used it before or seen it used so maybe its not to be used?</p> <pre><code>functi...
[ { "answer_id": 191163, "author": "birgire", "author_id": 26350, "author_profile": "https://wordpress.stackexchange.com/users/26350", "pm_score": 3, "selected": false, "text": "<p>Note that here you're overriding the paging of the main query, with the <code>posts_limits</code> filter, by ...
2015/06/11
[ "https://wordpress.stackexchange.com/questions/191160", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/9884/" ]
Because of the lack of documentation about [`post_limits`](https://codex.wordpress.org/Plugin_API/Filter_Reference/post_limits), its hard to learn more about this function and when to use it. Never used it before or seen it used so maybe its not to be used? ``` function wpcodex_filter_home_post_limits( $limit, $query ...
Note that here you're overriding the paging of the main query, with the `posts_limits` filter, by using hardcoded values: ``` 'LIMIT 0, 25' ``` where `0` is the offset and `25` is the number of posts to display. So in this case I would just use `pre_get_posts` with ``` $query->set( 'posts_per_page', 25 ); ``` an...
191,169
<p>So I've been tasked with making an "Image Advert" to be placed on a sidebar on this website. The client wants to have the ability to upload 5 images on to the ACF Options Page and then have a random image be pulled from there and displayed on the sidebar at random everytime the page refreshes.</p> <p>I was wonderin...
[ { "answer_id": 191171, "author": "TheDeadMedic", "author_id": 1685, "author_profile": "https://wordpress.stackexchange.com/users/1685", "pm_score": 1, "selected": true, "text": "<p>Just noticed the issue - since your ACF field is an options page, you need to pass the second argument <cod...
2015/06/11
[ "https://wordpress.stackexchange.com/questions/191169", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74521/" ]
So I've been tasked with making an "Image Advert" to be placed on a sidebar on this website. The client wants to have the ability to upload 5 images on to the ACF Options Page and then have a random image be pulled from there and displayed on the sidebar at random everytime the page refreshes. I was wondering if it wa...
Just noticed the issue - since your ACF field is an options page, you need to pass the second argument `options` to `get_field` - add a bit of sanity checking too: ``` $rows = get_field( 'image_advert_repeater', 'options' ); if ( ! empty( $rows ) && is_array( $rows ) ) { // Your code } ```
191,176
<p>Based on <a href="https://wordpress.stackexchange.com/questions/191120/how-to-check-if-widget-has-automatic-title/191154">this question</a>, I'm getting an error <code>Warning: Missing argument 2 for...</code>.</p> <p>This happens for some widgets those are created by plugins.</p> <p>-- Edit 1 --</p> <p>Here's a ...
[ { "answer_id": 191403, "author": "fuxia", "author_id": 73, "author_profile": "https://wordpress.stackexchange.com/users/73", "pm_score": 3, "selected": true, "text": "<p>You don’t pass more than argument to that filter, so any callback expecting more than one will not get it. The core ca...
2015/06/11
[ "https://wordpress.stackexchange.com/questions/191176", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/37529/" ]
Based on [this question](https://wordpress.stackexchange.com/questions/191120/how-to-check-if-widget-has-automatic-title/191154), I'm getting an error `Warning: Missing argument 2 for...`. This happens for some widgets those are created by plugins. -- Edit 1 -- Here's a simple widget that causes the error: ``` func...
You don’t pass more than argument to that filter, so any callback expecting more than one will not get it. The core calls this filter always like this: ``` $title = apply_filters( 'widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base ); ``` But you are pass...
191,178
<p>I have an own class that deregisters all scripts and styles and creates 2 cached files one for scripts and one for styles that is registered in the end. This runs inside theme, my problem is that I cant move it into plugin, as soon as i move it into plugin it wont work.</p> <p>currently this code works inside theme...
[ { "answer_id": 192566, "author": "Domain", "author_id": 26523, "author_profile": "https://wordpress.stackexchange.com/users/26523", "pm_score": 0, "selected": false, "text": "<p>Since plugins are loaded by the alphabetical order of plugin's folder name (not by plugin's name), name your p...
2015/06/11
[ "https://wordpress.stackexchange.com/questions/191178", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74531/" ]
I have an own class that deregisters all scripts and styles and creates 2 cached files one for scripts and one for styles that is registered in the end. This runs inside theme, my problem is that I cant move it into plugin, as soon as i move it into plugin it wont work. currently this code works inside theme ``` add_...
There's a much better and more reliable way than naming your plugin "ZZ" - use a delayed hook on `plugins_loaded`, which fires after all plugins are loaded: ``` function wpse_191178_plugins_loaded() { // Do your stuff } add_action( 'plugins_loaded', 'wpse_191178_plugins_loaded', 100 ); ```
191,210
<p>Writing my first Wordpress plugin that uses a Class approach.</p> <p>It is being called on a page via a shortcode. In testing, the shortcode is working and the shortcode specific php file is being loaded.</p> <p>However, the 2 add_action calls are not firing:</p> <pre><code>//Register Styles add_action( 'wp_enque...
[ { "answer_id": 191212, "author": "Milo", "author_id": 4771, "author_profile": "https://wordpress.stackexchange.com/users/4771", "pm_score": 3, "selected": true, "text": "<p>There is no action called <code>wp_enqueue_script</code>, it's <code>wp_enqueue_scripts</code>, plural, and both sc...
2015/06/11
[ "https://wordpress.stackexchange.com/questions/191210", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/68087/" ]
Writing my first Wordpress plugin that uses a Class approach. It is being called on a page via a shortcode. In testing, the shortcode is working and the shortcode specific php file is being loaded. However, the 2 add\_action calls are not firing: ``` //Register Styles add_action( 'wp_enqueue_style', array( $this, 'r...
There is no action called `wp_enqueue_script`, it's `wp_enqueue_scripts`, plural, and both scripts and styles should be enqueued on that action.
191,263
<p>I am working with woocomerce plugin. My woocomerce product display like this:</p> <pre><code>&lt;div class="product-box"&gt; &lt;a href="http://localhost/ebhajipala_latest/shop/health/veg14/"&gt; &lt;img class="attachment-shop_catalog wp-post-image" width="150" height="150" alt="download" src="http://loca...
[ { "answer_id": 191266, "author": "mmm", "author_id": 74311, "author_profile": "https://wordpress.stackexchange.com/users/74311", "pm_score": 0, "selected": false, "text": "<p>you have <code>wc_get_template_part( 'content', 'product' );</code> so you have to look in the file <code>content...
2015/06/12
[ "https://wordpress.stackexchange.com/questions/191263", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74574/" ]
I am working with woocomerce plugin. My woocomerce product display like this: ``` <div class="product-box"> <a href="http://localhost/ebhajipala_latest/shop/health/veg14/"> <img class="attachment-shop_catalog wp-post-image" width="150" height="150" alt="download" src="http://localhost/ebhajipala_latest/wp-co...
A quick solution: find your `content-product.php` find the below code ``` <a href="<?php the_permalink(); ?>"> <?php /** * woocommerce_before_shop_loop_item_title hook * * @hooked woocommerce_show_product_loop_sale_flash - 10 * @hooked woocommerc...
191,264
<p>I <em>need</em> a function that I can use that will remove &lt;div&gt; and &lt;/div&gt; tags from a string. I have tried <em>esc_attr()</em>, and even <em>wp_strip_all_tags()</em> --- none of them work. They all leave the &lt;div&gt; and &lt;/div&gt; tags in the string - which causes certain social-media buttons to ...
[ { "answer_id": 191269, "author": "ChrisL", "author_id": 70768, "author_profile": "https://wordpress.stackexchange.com/users/70768", "pm_score": 0, "selected": false, "text": "<p>If it's only &lt;div&gt;&lt;/div&gt; I would do a <a href=\"http://php.net/manual/de/function.preg-replace.ph...
2015/06/12
[ "https://wordpress.stackexchange.com/questions/191264", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/71557/" ]
I *need* a function that I can use that will remove <div> and </div> tags from a string. I have tried *esc\_attr()*, and even *wp\_strip\_all\_tags()* --- none of them work. They all leave the <div> and </div> tags in the string - which causes certain social-media buttons to turn out in ways that *really* do not look g...
Use a PHP function to do this: <https://php.net/strip_tags> example: ``` echo strip_tags("<div>my text</div>"); ```
191,273
<p>This is my first post on <em>WordPress StackExchange</em>, I'll try to be precise.</p> <blockquote> <p>My question is: <strong>Is there anything in particular I should do to the files I'm including in my theme's functions.php file?</strong></p> </blockquote> <p>I'm creating a WordPress theme and my <strong>funct...
[ { "answer_id": 191275, "author": "Pieter Goosen", "author_id": 31545, "author_profile": "https://wordpress.stackexchange.com/users/31545", "pm_score": 3, "selected": true, "text": "<p>I always break my functions.php up into more managable, specific functionality files, for instance, all ...
2015/06/12
[ "https://wordpress.stackexchange.com/questions/191273", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74575/" ]
This is my first post on *WordPress StackExchange*, I'll try to be precise. > > My question is: **Is there anything in particular I should do to the files I'm including in my theme's functions.php file?** > > > I'm creating a WordPress theme and my **functions.php** file is getting very big now. I managed to remo...
I always break my functions.php up into more managable, specific functionality files, for instance, all footer related functions goes into a file called `footer-functions.php` and pagination functions goes into a file called `pagination-functions.php`. This way, my code stays organised, managable and I don't kill my `f...
191,279
<p>Is it possible to change permalinks on all posts created after a certain date? This because we don't want old URLs to break.</p> <p>Now we have <code>/%year%/%month%/%postname%</code> We want to have <code>/%postname</code></p>
[ { "answer_id": 191343, "author": "Bruno Monteiro", "author_id": 36031, "author_profile": "https://wordpress.stackexchange.com/users/36031", "pm_score": -1, "selected": false, "text": "<p>You can create a new post type, under the name \"post\" and then add a rewrite slug. This will overwr...
2015/06/12
[ "https://wordpress.stackexchange.com/questions/191279", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/19188/" ]
Is it possible to change permalinks on all posts created after a certain date? This because we don't want old URLs to break. Now we have `/%year%/%month%/%postname%` We want to have `/%postname`
Your permalink structure is global; it is not a property of individual posts. There is no way to indicate that one post uses a certain permalink structure while another uses a different one. This makes sense when you think about how WordPress processes requests. Using the new structure, WordPress maps the request to `...
191,293
<p>I have a page where, with shortcode, I queried multiple posts from a CPT - so the page is one kind of archive page to the general users.</p> <pre><code>Page Title - CPT Post Title #1 - CPT Post Title #2 - CPT Post Title #3 </code></pre> <p>In certain condition I want to alter only the Page Title, not CPT Pos...
[ { "answer_id": 191297, "author": "Pieter Goosen", "author_id": 31545, "author_profile": "https://wordpress.stackexchange.com/users/31545", "pm_score": 3, "selected": true, "text": "<p>I believe that the page title you are talking about is the title from the page from the main query. <cod...
2015/06/12
[ "https://wordpress.stackexchange.com/questions/191293", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/22728/" ]
I have a page where, with shortcode, I queried multiple posts from a CPT - so the page is one kind of archive page to the general users. ``` Page Title - CPT Post Title #1 - CPT Post Title #2 - CPT Post Title #3 ``` In certain condition I want to alter only the Page Title, not CPT Post Title. I tried: ``` fun...
I believe that the page title you are talking about is the title from the page from the main query. `the_title()` filter (and `the_content()` filter for that matter) targets all the respective template tags regardless of query. To avoid this, target only the main query and the specific page. You can try the followi...
191,296
<p>So I'm trying to save the value of a custom term to my database. The table is created as is the custom term. The code below outputs the text field onto my custom terms page but it just doesn't save any value to the database. </p> <p>Can anyone see if there's anything wrong with this? (I'm sure there's something I'...
[ { "answer_id": 191297, "author": "Pieter Goosen", "author_id": 31545, "author_profile": "https://wordpress.stackexchange.com/users/31545", "pm_score": 3, "selected": true, "text": "<p>I believe that the page title you are talking about is the title from the page from the main query. <cod...
2015/06/12
[ "https://wordpress.stackexchange.com/questions/191296", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/67320/" ]
So I'm trying to save the value of a custom term to my database. The table is created as is the custom term. The code below outputs the text field onto my custom terms page but it just doesn't save any value to the database. Can anyone see if there's anything wrong with this? (I'm sure there's something I've missed)...
I believe that the page title you are talking about is the title from the page from the main query. `the_title()` filter (and `the_content()` filter for that matter) targets all the respective template tags regardless of query. To avoid this, target only the main query and the specific page. You can try the followi...
191,299
<p>I've been learning to convert HTML to WordPress and want to convert on to class like this:</p> <pre><code>&lt;div class="mainmenu pull-left"&gt; &lt;ul class="nav navbar-nav collapse navbar-collapse"&gt; &lt;li&gt;&lt;a href="index.html" class="active"&gt;Home&lt;/a&gt;&lt;/li&gt; &lt;li class="...
[ { "answer_id": 191309, "author": "ChrisL", "author_id": 70768, "author_profile": "https://wordpress.stackexchange.com/users/70768", "pm_score": 3, "selected": false, "text": "<p>You already did it the right way. If you take a look in the Documentation for <a href=\"https://developer.word...
2015/06/12
[ "https://wordpress.stackexchange.com/questions/191299", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74591/" ]
I've been learning to convert HTML to WordPress and want to convert on to class like this: ``` <div class="mainmenu pull-left"> <ul class="nav navbar-nav collapse navbar-collapse"> <li><a href="index.html" class="active">Home</a></li> <li class="dropdown"><a href="#">Shop<i class="fa fa-angle-down"...
You already did it the right way. If you take a look in the Documentation for [wp\_nav\_menu](https://developer.wordpress.org/reference/functions/wp_nav_menu/), you'll see that menu\_class is the right option for the UL's class: ``` wp_nav_menu( array( 'theme_location' => 'top-menu', 'container' => '', 'me...
191,310
<p>I have been developing a WordPress website for a client, working from my own machine utilizing WAMP to create a local environment on which to work.</p> <p>Now, the problem is that the website needs to go live. I understand how to use an FTP client, and that's not a problem. I have the details for the domain etc. Th...
[ { "answer_id": 191323, "author": "TheGentleman", "author_id": 68563, "author_profile": "https://wordpress.stackexchange.com/users/68563", "pm_score": 0, "selected": false, "text": "<p>If your client's existing site is a wordpress site and you just want to use your new theme then you can ...
2015/06/12
[ "https://wordpress.stackexchange.com/questions/191310", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74597/" ]
I have been developing a WordPress website for a client, working from my own machine utilizing WAMP to create a local environment on which to work. Now, the problem is that the website needs to go live. I understand how to use an FTP client, and that's not a problem. I have the details for the domain etc. There is an ...
**Moving your sites** My recommendation would be to use the the [duplicator](https://wordpress.org/plugins/duplicator/) plugin. Far and away the easiest method I've used to back-up, move, and restore sites from local to production or from one host to another. If the old site is WordPress - sounds like it is, you may ...
191,313
<p>I have a plugin that is using Class style programming. I'm completely stumped - scripts are being loaded on every single page, even if the plugin is not being used on that page.</p> <p>Since the plugin should only run when one of its shortcodes are called, I don't understand why they are always being enqueued. The ...
[ { "answer_id": 191314, "author": "Rarst", "author_id": 847, "author_profile": "https://wordpress.stackexchange.com/users/847", "pm_score": 0, "selected": false, "text": "<p>You are answering your own question — scripts are being enqueued because that's what plugin does every load <em>unc...
2015/06/12
[ "https://wordpress.stackexchange.com/questions/191313", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/68087/" ]
I have a plugin that is using Class style programming. I'm completely stumped - scripts are being loaded on every single page, even if the plugin is not being used on that page. Since the plugin should only run when one of its shortcodes are called, I don't understand why they are always being enqueued. The code is: ...
As Rarst already noted, you answered your question. You are telling the software to load those scripts all the time. You need to control that process. Software is stupid. It can't decide when a good time is to load the code. SO... > > Since the plugin should only run when one of its shortcodes are > called, ... > >...
191,349
<p>The problem began with the wp upgrade redirect loop</p> <p>I tried to fix it by renaming one of the table value fors wp_options on php admin </p> <p>As a result of this I cannot log into my site anymore ..it gives the redirect loop. Furthermore, there is a bunch of gibberish all over my site with error messages h...
[ { "answer_id": 191378, "author": "tman16", "author_id": 74622, "author_profile": "https://wordpress.stackexchange.com/users/74622", "pm_score": 0, "selected": false, "text": "<p>Have you tried creating a new database, upload your backup to it - then redirect wordpress to use this instead...
2015/06/12
[ "https://wordpress.stackexchange.com/questions/191349", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74611/" ]
The problem began with the wp upgrade redirect loop I tried to fix it by renaming one of the table value fors wp\_options on php admin As a result of this I cannot log into my site anymore ..it gives the redirect loop. Furthermore, there is a bunch of gibberish all over my site with error messages hen I try to debug...
After 6 hours of trial and error, I deleted my site, uploaded an older version of wordpress, made a new database, re-named the plugin folder (so that there would be no plugins), and uploaded my most recent database back-up..and then it worked. I was able to login and all my page were restored. The problem may have been...
191,384
<p>I have the following working code for a query on a specific category and tag slug:</p> <pre><code>$args = array( 'category_name' =&gt; $cat_name, 'tag' =&gt; $tag_name, 'post__not_in' =&gt; $sticky ); $my_query = new WP_Query( $args ); </code></pre> <p>I can't figure out how to exclude a specific tag name from ...
[ { "answer_id": 191385, "author": "sakibmoon", "author_id": 23214, "author_profile": "https://wordpress.stackexchange.com/users/23214", "pm_score": 3, "selected": false, "text": "<p>Use <code>tag__not_in</code> parameter. You have to use tag ID for this parameter</p>\n\n<pre><code>$args =...
2015/06/13
[ "https://wordpress.stackexchange.com/questions/191384", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/45758/" ]
I have the following working code for a query on a specific category and tag slug: ``` $args = array( 'category_name' => $cat_name, 'tag' => $tag_name, 'post__not_in' => $sticky ); $my_query = new WP_Query( $args ); ``` I can't figure out how to exclude a specific tag name from the query. Do I need the tag ID? Ho...
Use `tag__not_in` parameter. You have to use tag ID for this parameter ``` $args = array( 'category_name' => $cat_name, 'tag' => $tag_name, 'post__not_in' => $sticky, 'tag__not_in' => array($tag_id_1, $tag_id_2) ); $my_query = new WP_Query( $args ); ```
191,418
<p>I am struggling with a common issue that many people appear to have encountered over the years. In creating a widget I need a series of radio buttons. Using the code below I can create and show the radio buttons, yet it does not seem to save the value to the database, showing all as unchecked when I hit the save but...
[ { "answer_id": 191447, "author": "Allen Tullett", "author_id": 63400, "author_profile": "https://wordpress.stackexchange.com/users/63400", "pm_score": 2, "selected": false, "text": "<p>Got it, it turns out...</p>\n\n<ol>\n<li>The label for each radio button must be the field id / variabl...
2015/06/14
[ "https://wordpress.stackexchange.com/questions/191418", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/63400/" ]
I am struggling with a common issue that many people appear to have encountered over the years. In creating a widget I need a series of radio buttons. Using the code below I can create and show the radio buttons, yet it does not seem to save the value to the database, showing all as unchecked when I hit the save button...
Got it, it turns out... 1. The label for each radio button must be the field id / variable, in my example is 'radio\_buttons' 2. The IF statement for each radio button must refer to this same ID - **$radio\_buttons === 'radio\_option\_1'** & **$radio\_buttons === 'radio\_option\_2'** My new code which works is... ``...
191,423
<p>I've checked any threads here regarding this and did a debug test which worked, I'd like to understand why my own code doesn't work as it presents the same functionality explained in every possible thread created about this issue.</p> <p>I'm trying to send AJAX request when clicking on a checkbox and do some work w...
[ { "answer_id": 195869, "author": "Y. E.", "author_id": 76640, "author_profile": "https://wordpress.stackexchange.com/users/76640", "pm_score": 1, "selected": false, "text": "<p>Placing this answer for those people who're trying to fix the same issue.</p>\n\n<p>It's important where </p>\n...
2015/06/14
[ "https://wordpress.stackexchange.com/questions/191423", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74605/" ]
I've checked any threads here regarding this and did a debug test which worked, I'd like to understand why my own code doesn't work as it presents the same functionality explained in every possible thread created about this issue. I'm trying to send AJAX request when clicking on a checkbox and do some work with MySQL....
The problem is where you place the add\_action of your wp\_ajax\_\* Try to put it at the start of everything, and ensuring that it is being loaded in a /wp-admin/ route. Try your url: <http://xxx/wp-admin/admin-ajax.php?action=your_action> until it gives you something different than zero.
191,461
<p>I am currently developing a one-page based layout with WordPress where the actual content is split up into separate pages in the backend, which are all knit together to a one-page layout in my front-page template file. </p> <p>The WordPress menus allow for custom URLs which is probably the easiest way to cater a on...
[ { "answer_id": 191496, "author": "Kristoffer", "author_id": 74683, "author_profile": "https://wordpress.stackexchange.com/users/74683", "pm_score": 0, "selected": false, "text": "<p>I'm currently doing this on a project.</p>\n\n<p>First, I use the slug to create the anchor on the onepage...
2015/06/14
[ "https://wordpress.stackexchange.com/questions/191461", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25245/" ]
I am currently developing a one-page based layout with WordPress where the actual content is split up into separate pages in the backend, which are all knit together to a one-page layout in my front-page template file. The WordPress menus allow for custom URLs which is probably the easiest way to cater a one-pager by...
Well, after some more intense research I finally found a viable solution that is clean and simple and works flawless so far. Just put this into your functions.php to create a custom walker which turns classic permalinks into hashes (e.g. page.com/mypage to page.com/#mypage): ``` /* Custom nav walker */ class Single...
191,471
<p>I'm trying to set up my custom template for a custom taxonomy. When I click on a category link to display the custom posts in that specific category, I get the 404 page. My custom post type file name is template-features.php and my taxonomy archive file is archive-features.php. Here is my code to register the taxono...
[ { "answer_id": 191473, "author": "Hareesh Sivasubramanian", "author_id": 59124, "author_profile": "https://wordpress.stackexchange.com/users/59124", "pm_score": 0, "selected": false, "text": "<p>Did you remember to <a href=\"https://codex.wordpress.org/Function_Reference/flush_rewrite_ru...
2015/06/15
[ "https://wordpress.stackexchange.com/questions/191471", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/13096/" ]
I'm trying to set up my custom template for a custom taxonomy. When I click on a category link to display the custom posts in that specific category, I get the 404 page. My custom post type file name is template-features.php and my taxonomy archive file is archive-features.php. Here is my code to register the taxonomy ...
From code for post type and custom taxonomy, your CPT is `post_features` and taxonomy is `features`. For single `post_features`, you need to have file named `single-post_features.php`. For archive, create file `taxonomy-features.php`. See documentation for detail. <https://codex.wordpress.org/Post_Type_Templates> **...
191,479
<p>In <a href="https://make.wordpress.org/core/2015/04/23/spinners-and-dismissible-admin-notices-in-4-2/" rel="noreferrer">WordPress 4.2</a> the <code>is-dismissible</code> class was introduced to allow notices to be dismissed.</p> <p>This code is working to add the notice.</p> <pre><code>function prefix_deprecated_h...
[ { "answer_id": 193573, "author": "grappler", "author_id": 17937, "author_profile": "https://wordpress.stackexchange.com/users/17937", "pm_score": 0, "selected": false, "text": "<p>The best solution I found was a small library. <a href=\"https://github.com/CalderaWP/dismissible_notice\" r...
2015/06/15
[ "https://wordpress.stackexchange.com/questions/191479", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/17937/" ]
In [WordPress 4.2](https://make.wordpress.org/core/2015/04/23/spinners-and-dismissible-admin-notices-in-4-2/) the `is-dismissible` class was introduced to allow notices to be dismissed. This code is working to add the notice. ``` function prefix_deprecated_hook_admin_notice() { if ( has_filter( 'prefix_filter' ) ...
There's no need for a library, it's fairly straightforward to accomplish. If you are coding your own plugin (which it appears you are), then you can do this in a fairly lightweight way: A slightly modified version of the notice, which checks if it's been dismissed before displaying, and stores the "type" of notice in ...
191,481
<p>I know there are userID, username in the database, but I want a formatted and unique number for physical world use. For example: "2014xxxx" 201414:year,xxxx:generate randomly when registering a user. </p> <p>Is it possible and if possible, what is the simplest way and fastest way to do so? </p>
[ { "answer_id": 193573, "author": "grappler", "author_id": 17937, "author_profile": "https://wordpress.stackexchange.com/users/17937", "pm_score": 0, "selected": false, "text": "<p>The best solution I found was a small library. <a href=\"https://github.com/CalderaWP/dismissible_notice\" r...
2015/06/15
[ "https://wordpress.stackexchange.com/questions/191481", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74676/" ]
I know there are userID, username in the database, but I want a formatted and unique number for physical world use. For example: "2014xxxx" 201414:year,xxxx:generate randomly when registering a user. Is it possible and if possible, what is the simplest way and fastest way to do so?
There's no need for a library, it's fairly straightforward to accomplish. If you are coding your own plugin (which it appears you are), then you can do this in a fairly lightweight way: A slightly modified version of the notice, which checks if it's been dismissed before displaying, and stores the "type" of notice in ...
191,522
<p>I search a lot that how can i re-size images that upload with meta field but i get nothing instead of <code>wp_get_image_editor</code>. I read from codex about it but nothing helpful so I search about this function and found these links</p> <p><a href="http://bhoover.com/wp_image_editor-wordpress-image-editing-tuto...
[ { "answer_id": 220660, "author": "iantsch", "author_id": 90220, "author_profile": "https://wordpress.stackexchange.com/users/90220", "pm_score": 2, "selected": true, "text": "<h2>A possible solution:</h2>\n\n<p><strong>Goal:</strong> Don't use <code>add_image_size()</code> to show a cust...
2015/06/15
[ "https://wordpress.stackexchange.com/questions/191522", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64316/" ]
I search a lot that how can i re-size images that upload with meta field but i get nothing instead of `wp_get_image_editor`. I read from codex about it but nothing helpful so I search about this function and found these links <http://bhoover.com/wp_image_editor-wordpress-image-editing-tutorial/> <http://wpunknown.com...
A possible solution: -------------------- **Goal:** Don't use `add_image_size()` to show a custom sized image. If you calculate the image without saving it, all requests will sum up to a huge page load due to repeated unnecessary processing time. So caching or saving the results should be an additional goal. Add a *...
191,523
<p>In my themes functions.php file I have put:</p> <pre><code>add_action('wp_footer', 'method'); function method() { echo "this is being called"; die(); } </code></pre> <p>My wordpress footer.php file looks like this:</p> <pre><code>&lt;?php wp_footer(); ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>What coul...
[ { "answer_id": 191535, "author": "Brad Elsmore", "author_id": 69036, "author_profile": "https://wordpress.stackexchange.com/users/69036", "pm_score": 0, "selected": false, "text": "<p>With such a general function name like <code>method()</code> a collision could be happening. Try somethi...
2015/06/15
[ "https://wordpress.stackexchange.com/questions/191523", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/73967/" ]
In my themes functions.php file I have put: ``` add_action('wp_footer', 'method'); function method() { echo "this is being called"; die(); } ``` My wordpress footer.php file looks like this: ``` <?php wp_footer(); ?> </body> </html> ``` What could be the reason my add\_action hook is not being called? I can pro...
In a WordPress footer hooks are different for back-end(dashboard) and front-end. In Dashboard use "`admin_footer`" hook. In Front-end use "`wp_footer`" hook.
191,558
<p>Is there any way to disable the installation/updating of plugins in Wordpress?</p> <p>I am deploying by Github, and therefore changes on server, does not replicate on my development environment. </p> <p>I need to disable this, and make all updates and installations on my local Git repository, and THEN push to prod...
[ { "answer_id": 191559, "author": "Rarst", "author_id": 847, "author_profile": "https://wordpress.stackexchange.com/users/847", "pm_score": 0, "selected": false, "text": "<p>There are quite a few related bits you can tinker with, but the one most comprehensive setting for version controll...
2015/06/15
[ "https://wordpress.stackexchange.com/questions/191558", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25242/" ]
Is there any way to disable the installation/updating of plugins in Wordpress? I am deploying by Github, and therefore changes on server, does not replicate on my development environment. I need to disable this, and make all updates and installations on my local Git repository, and THEN push to production, with the ...
Set the constant `DISALLOW_FILE_MODS` to `TRUE` in your `wp-config.php`: ``` const DISALLOW_FILE_MODS = TRUE; ``` See [the Codex](https://codex.wordpress.org/Editing_wp-config.php#Disable_the_Plugin_and_Theme_Editor) for background information: > > Setting this constant also disables the Plugin and Theme editor (i...
191,571
<p>I have many post with multiple tags ex: <code>AMOS LEE, FOO FIGHTERS,TAYLOR SWIFT</code></p> <p>Post only have one of the tags in the title ex: <code>“The Man Who Wants You” – Amos Lee</code></p> <p>How would I scan the_title() and go through the tags and store the matching tag in a variable? </p> <p>Ive tried</p...
[ { "answer_id": 191619, "author": "James Barrett", "author_id": 74733, "author_profile": "https://wordpress.stackexchange.com/users/74733", "pm_score": 2, "selected": true, "text": "<p>Put this in your loop:</p>\n\n<pre><code>&lt;?php\n$title = get_the_title();\n$posttags = get_the_tags()...
2015/06/15
[ "https://wordpress.stackexchange.com/questions/191571", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/63922/" ]
I have many post with multiple tags ex: `AMOS LEE, FOO FIGHTERS,TAYLOR SWIFT` Post only have one of the tags in the title ex: `“The Man Who Wants You” – Amos Lee` How would I scan the\_title() and go through the tags and store the matching tag in a variable? Ive tried ``` <?php $id = get_the_title(); $posttags ...
Put this in your loop: ``` <?php $title = get_the_title(); $posttags = get_the_tags(); if( $title && $posttags ) { $result = find_tag_in_title( $title, $posttags ); var_dump( $result ); // dump result } ?> ``` Put this in your functions.php file: ``` <?php function find_tag_in_title( $title, $posttags ) { f...
191,587
<p>I'll admit, I'm not a PHP expert, nor am I familiar with all of the WordPress functions and hooks. I've been stuck on an issue, searching for help without much success, and I was hoping that someone could help point me in the right direction.</p> <p>I have a form. The user selects a specialty, location, and distanc...
[ { "answer_id": 192175, "author": "zaantar", "author_id": 75006, "author_profile": "https://wordpress.stackexchange.com/users/75006", "pm_score": -1, "selected": false, "text": "<p>It seems that you could use Types and Views plugins (with Views \"Parametric search\" feature). Views is com...
2015/06/16
[ "https://wordpress.stackexchange.com/questions/191587", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/-1/" ]
I'll admit, I'm not a PHP expert, nor am I familiar with all of the WordPress functions and hooks. I've been stuck on an issue, searching for help without much success, and I was hoping that someone could help point me in the right direction. I have a form. The user selects a specialty, location, and distance (10 mile...
here is the mysql query you can use to get the result having distance less then your value. ``` SELECT * , pm1.meta_value as latitude, pm2.meta_value as longitude , (((acos(sin(([latitude]*pi()/180)) * sin((pm1.meta_value * pi()/180)) + cos(([latitude]*pi()/180)) * cos((pm1.meta_value ...
191,592
<p>I have an archive that shows all the post on monthly now i want is to group them per year like</p> <pre><code>2015 Jan Feb March 2014 April May </code></pre> <p>I'm using this code.</p> <pre><code>&lt;?php wp_get_archives( array( 'type' =&gt; 'monthly' ) ); ?&gt; </code></pre> <p>This displays all the arch...
[ { "answer_id": 191602, "author": "Robert hue", "author_id": 22461, "author_profile": "https://wordpress.stackexchange.com/users/22461", "pm_score": 1, "selected": false, "text": "<p>To display monthly archives arranged by year, you can use this code. It checks through each month if WordP...
2015/06/16
[ "https://wordpress.stackexchange.com/questions/191592", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/62183/" ]
I have an archive that shows all the post on monthly now i want is to group them per year like ``` 2015 Jan Feb March 2014 April May ``` I'm using this code. ``` <?php wp_get_archives( array( 'type' => 'monthly' ) ); ?> ``` This displays all the archive monthly from the beginning. i tried to add a monthly a...
To display monthly archives arranged by year, you can use this code. It checks through each month if WordPress have any post in that month and create archive. ``` <?php global $wpdb; $limit = 0; $year_prev = null; $months = $wpdb->get_results( "SELECT DISTINCT MONTH( post_date ) AS month , YEAR( post_...
191,658
<p>I would want to allow certain user to edit only one page and it's subpages. How would this be possible? I tried the old Role Scoper, but it seems to have a lot of problems and bugs.</p>
[ { "answer_id": 191661, "author": "user2319361", "author_id": 74760, "author_profile": "https://wordpress.stackexchange.com/users/74760", "pm_score": -1, "selected": false, "text": "<p>I used <code>User Role Editor</code> a couple of times and is pretty good.\nMaybe it could help you too....
2015/06/16
[ "https://wordpress.stackexchange.com/questions/191658", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74762/" ]
I would want to allow certain user to edit only one page and it's subpages. How would this be possible? I tried the old Role Scoper, but it seems to have a lot of problems and bugs.
The first thing to do to implements such task is to be able to recognise which page an user can edit. There are different ways to do it. It could be a user meta, some configuration value... For the sake of this answer, I will assume that a function lile this exists: ``` function wpse_user_can_edit( $user_id, $page_id...
191,674
<p>I have a property website with a custom search form for minimum and maximum square feet.</p> <p>A registered user executes a search with a min(i.e. 150 sqft) and max(i.e. 300 sqft) select option value. </p> <p>I managed already to store inside cookies the min and max values. </p> <p>Then the user is able to click...
[ { "answer_id": 191661, "author": "user2319361", "author_id": 74760, "author_profile": "https://wordpress.stackexchange.com/users/74760", "pm_score": -1, "selected": false, "text": "<p>I used <code>User Role Editor</code> a couple of times and is pretty good.\nMaybe it could help you too....
2015/06/16
[ "https://wordpress.stackexchange.com/questions/191674", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74398/" ]
I have a property website with a custom search form for minimum and maximum square feet. A registered user executes a search with a min(i.e. 150 sqft) and max(i.e. 300 sqft) select option value. I managed already to store inside cookies the min and max values. Then the user is able to click on a "save this search"...
The first thing to do to implements such task is to be able to recognise which page an user can edit. There are different ways to do it. It could be a user meta, some configuration value... For the sake of this answer, I will assume that a function lile this exists: ``` function wpse_user_can_edit( $user_id, $page_id...
191,694
<p>From the <code>get_posts</code> docs I see it takes categories as a parameter.</p> <p>However, is this an <code>AND</code> or an <code>OR</code>?</p> <p>i.e. if you specify 2 categories do posts have to be in both to be returned?</p> <p>If not, how do you specify an <code>AND</code> relation? I only want posts th...
[ { "answer_id": 191661, "author": "user2319361", "author_id": 74760, "author_profile": "https://wordpress.stackexchange.com/users/74760", "pm_score": -1, "selected": false, "text": "<p>I used <code>User Role Editor</code> a couple of times and is pretty good.\nMaybe it could help you too....
2015/06/16
[ "https://wordpress.stackexchange.com/questions/191694", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/48904/" ]
From the `get_posts` docs I see it takes categories as a parameter. However, is this an `AND` or an `OR`? i.e. if you specify 2 categories do posts have to be in both to be returned? If not, how do you specify an `AND` relation? I only want posts that match ALL categories.
The first thing to do to implements such task is to be able to recognise which page an user can edit. There are different ways to do it. It could be a user meta, some configuration value... For the sake of this answer, I will assume that a function lile this exists: ``` function wpse_user_can_edit( $user_id, $page_id...
191,704
<p>I have a form:</p> <pre><code>&lt;form name="customer_details" method="POST" onsubmit="return form_validation()" action="../customer-details.php"&gt; </code></pre> <p>I placed the PHP file in my theme folder, but WordPress gives me an error:</p> <blockquote> <p>404 — Fancy meeting you here!</p> </blockquot...
[ { "answer_id": 191661, "author": "user2319361", "author_id": 74760, "author_profile": "https://wordpress.stackexchange.com/users/74760", "pm_score": -1, "selected": false, "text": "<p>I used <code>User Role Editor</code> a couple of times and is pretty good.\nMaybe it could help you too....
2015/06/16
[ "https://wordpress.stackexchange.com/questions/191704", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74798/" ]
I have a form: ``` <form name="customer_details" method="POST" onsubmit="return form_validation()" action="../customer-details.php"> ``` I placed the PHP file in my theme folder, but WordPress gives me an error: > > 404 — Fancy meeting you here! > > >
The first thing to do to implements such task is to be able to recognise which page an user can edit. There are different ways to do it. It could be a user meta, some configuration value... For the sake of this answer, I will assume that a function lile this exists: ``` function wpse_user_can_edit( $user_id, $page_id...
191,711
<p>I have a WordPress install using a Comodo SSL certificate. I have the <a href="https://wordpress.org/plugins/wordpress-https/" rel="nofollow noreferrer">WordPress HTTPS plugin</a> installed and I'm using the AZ theme, and the admin is set to load over HTTPS. So far so good.</p> <p>On the theme customizer, I get a p...
[ { "answer_id": 236160, "author": "Ethan O'Sullivan", "author_id": 98212, "author_profile": "https://wordpress.stackexchange.com/users/98212", "pm_score": 2, "selected": true, "text": "<p>Based on your question, I assume this is the plugin you are using to enable SSL: <a href=\"https://wo...
2015/06/17
[ "https://wordpress.stackexchange.com/questions/191711", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74800/" ]
I have a WordPress install using a Comodo SSL certificate. I have the [WordPress HTTPS plugin](https://wordpress.org/plugins/wordpress-https/) installed and I'm using the AZ theme, and the admin is set to load over HTTPS. So far so good. On the theme customizer, I get a perpetual loading icon (not to be confused with ...
Based on your question, I assume this is the plugin you are using to enable SSL: [WordPress HTTPS](https://wordpress.org/plugins/wordpress-https). Considering that the plugin hasn't been updated in two years and their support questions haven't been resolved, there may be some compatibility issues with the latest versi...
191,715
<p>I built a custom post type "shop" with <a href="https://wordpress.org/plugins/custom-post-type-ui/" rel="nofollow">Custom Post Type UI</a> plugin and added a field "address" (Google Map type) with <a href="https://wordpress.org/plugins/advanced-custom-fields/" rel="nofollow">Advanced Custom Fields</a> plugin.</p> <...
[ { "answer_id": 191717, "author": "s_ha_dum", "author_id": 21376, "author_profile": "https://wordpress.stackexchange.com/users/21376", "pm_score": 3, "selected": true, "text": "<p>You need a <a href=\"https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters\" rel=\"nof...
2015/06/17
[ "https://wordpress.stackexchange.com/questions/191715", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/3608/" ]
I built a custom post type "shop" with [Custom Post Type UI](https://wordpress.org/plugins/custom-post-type-ui/) plugin and added a field "address" (Google Map type) with [Advanced Custom Fields](https://wordpress.org/plugins/advanced-custom-fields/) plugin. From the response of `WP_Query('post_type=shop');`, I got th...
You need a [`meta_query`](https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters) something like this: ``` $args = array( 'post_type' => 'shop', 'meta_query' => array( array( 'key' => 'map-location', 'value' => 'London', 'compare' => 'LIKE' // t...
191,729
<p>Since WP3.5, <code>prepare()</code> accepts placeholders as a security measure, instead of just appending the argument to the query. Therefore, <code>$wpdb-&gt;prefix</code> needs to become a second parameter, called by <code>%s</code>:</p> <pre><code>$count = $wpdb-&gt;get_var( $wpdb-&gt;prepare( "SELECT COUNT(id...
[ { "answer_id": 191731, "author": "s_ha_dum", "author_id": 21376, "author_profile": "https://wordpress.stackexchange.com/users/21376", "pm_score": 4, "selected": true, "text": "<blockquote>\n <p>How can I fix this?</p>\n</blockquote>\n\n<p>You can't, but it isn't broken. You are telling ...
2015/06/17
[ "https://wordpress.stackexchange.com/questions/191729", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/373/" ]
Since WP3.5, `prepare()` accepts placeholders as a security measure, instead of just appending the argument to the query. Therefore, `$wpdb->prefix` needs to become a second parameter, called by `%s`: ``` $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM %s WHERE answer !=' '", $wpdb->prefix . "faq_quest...
> > How can I fix this? > > > You can't, but it isn't broken. You are telling `prepare` to use a string. A string will be quoted. It isn't meant to generate MySQL syntax, which is what you are asking it to do. Your tablename is more a MySQL command or keyword than a string value. That isn't what `prepare` is for. ...
191,730
<p>I am running a dwfocus news website, I would like to split my li loop catagory in two section, can some let me know how can i proceed forward, thanks.</p> <pre><code>&lt;div class="headlines" data-interval="&lt;?php echo ($interval&gt;0)?$interval*1000:'false'; ?&gt;"&gt; &lt;ul&gt; &lt;?php ...
[ { "answer_id": 191733, "author": "Junaid", "author_id": 73812, "author_profile": "https://wordpress.stackexchange.com/users/73812", "pm_score": 3, "selected": true, "text": "<p>You will need to create <code>css</code> classes for a left and right column (you can use bootstrap if you like...
2015/06/17
[ "https://wordpress.stackexchange.com/questions/191730", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74812/" ]
I am running a dwfocus news website, I would like to split my li loop catagory in two section, can some let me know how can i proceed forward, thanks. ``` <div class="headlines" data-interval="<?php echo ($interval>0)?$interval*1000:'false'; ?>"> <ul> <?php $i = 0; while ( $r-...
You will need to create `css` classes for a left and right column (you can use bootstrap if you like) after creating the classes try this ``` <div class="headlines" data-interval="<?php echo ($interval>0)?$interval*1000:'false'; ?>"> <ul> <?php $i = 0; while ( $r->have_posts() ) { ...
191,748
<p>I have custom post type called <code>event</code>, which has custom fields for <code>start_date</code> and <code>end_date</code>. For the event archive, I'm filtering out "expired" events using the following meta query added to the main query inside a <code>pre_get_posts</code> filter, which works fine:</p> <pre><c...
[ { "answer_id": 191750, "author": "Mats Mikkel Rummelhoff", "author_id": 68466, "author_profile": "https://wordpress.stackexchange.com/users/68466", "pm_score": 3, "selected": true, "text": "<p>In the case that the <code>start_date</code> custom field only exists for the <code>event</code...
2015/06/17
[ "https://wordpress.stackexchange.com/questions/191748", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/68466/" ]
I have custom post type called `event`, which has custom fields for `start_date` and `end_date`. For the event archive, I'm filtering out "expired" events using the following meta query added to the main query inside a `pre_get_posts` filter, which works fine: ``` if ( is_post_type_archive( 'event' ) ) { $query->s...
In the case that the `start_date` custom field only exists for the `event` post type, this works: ``` $query->set( 'meta_query', array( 'relation' => 'OR', array( 'key' => 'start_date', 'compare' => 'NOT EXISTS', ), array( 'key' => 'start_date', 'value' => $today = date(...
191,752
<p>We have 2 WordPress sites in 2 different sub-domains like <strong>test1.abc.com</strong> and <strong>test2.abc.com</strong> . Both sites have <strong>wp-require</strong> plugin activated and only logged-in users can see the site. We want to make a system where if a user logged into one site, he should be auto-login ...
[ { "answer_id": 191753, "author": "Mitul", "author_id": 74728, "author_profile": "https://wordpress.stackexchange.com/users/74728", "pm_score": 0, "selected": false, "text": "<p>Hi Multisite User Management plugin will help you </p>\n\n<p><a href=\"https://wordpress.org/plugins/multisite-...
2015/06/17
[ "https://wordpress.stackexchange.com/questions/191752", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74820/" ]
We have 2 WordPress sites in 2 different sub-domains like **test1.abc.com** and **test2.abc.com** . Both sites have **wp-require** plugin activated and only logged-in users can see the site. We want to make a system where if a user logged into one site, he should be auto-login into the other one. **What I did:** Afte...
See [my answer on this exact problem](https://wordpress.stackexchange.com/a/183750/1685). Long story short, you also need to define `COOKIEHASH`, otherwise the login cookie names will be different for each site: ``` define( 'COOKIEHASH', 'randomhash' ); ``` Make sure to change `randomhash` to a real hash, you can [g...
191,771
<p>I have static front page for my WP installation set from <code>settings &gt; reading</code>. Then I have added a URL endpoint using.</p> <pre><code>add_rewrite_endpoint('foo', EP_ALL); </code></pre> <p>So, the front page should be accessible via</p> <pre><code>http://example.com/ http://example.com/foo http://exa...
[ { "answer_id": 191753, "author": "Mitul", "author_id": 74728, "author_profile": "https://wordpress.stackexchange.com/users/74728", "pm_score": 0, "selected": false, "text": "<p>Hi Multisite User Management plugin will help you </p>\n\n<p><a href=\"https://wordpress.org/plugins/multisite-...
2015/06/17
[ "https://wordpress.stackexchange.com/questions/191771", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/3094/" ]
I have static front page for my WP installation set from `settings > reading`. Then I have added a URL endpoint using. ``` add_rewrite_endpoint('foo', EP_ALL); ``` So, the front page should be accessible via ``` http://example.com/ http://example.com/foo http://example.com/foo/bar ``` For #1 Everything works fine...
See [my answer on this exact problem](https://wordpress.stackexchange.com/a/183750/1685). Long story short, you also need to define `COOKIEHASH`, otherwise the login cookie names will be different for each site: ``` define( 'COOKIEHASH', 'randomhash' ); ``` Make sure to change `randomhash` to a real hash, you can [g...
191,772
<p>I have created a theme for one of our clients using bootstrap framework!</p> <p>When i was working on it on Localhost it works Correctly, but when I Uploaded it doesn't work. When I Activate it from Appearance I Saw A blank white Page; Also when I Try to Post a new Comment, post, page or custom post type.</p> <p>I...
[ { "answer_id": 191774, "author": "Bruno Monteiro", "author_id": 36031, "author_profile": "https://wordpress.stackexchange.com/users/36031", "pm_score": 3, "selected": true, "text": "<p>This answer will be long, but can be helpful in some way.</p>\n<h1>First of all, detect why you're gett...
2015/06/17
[ "https://wordpress.stackexchange.com/questions/191772", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/73590/" ]
I have created a theme for one of our clients using bootstrap framework! When i was working on it on Localhost it works Correctly, but when I Uploaded it doesn't work. When I Activate it from Appearance I Saw A blank white Page; Also when I Try to Post a new Comment, post, page or custom post type. Is there any Help ...
This answer will be long, but can be helpful in some way. First of all, detect why you're getting this error: =================================================== Majority of the time when you see a **Wordpress' White Screen of Death**, it means that you **exhausted the memory limit** of your server settings. This co...
191,775
<p>I got a fatal error in existing code, when I debug deeper I found that it was coming from bellow line.</p> <pre><code>get_posts( array("posts_per_page"=&gt;-1) ); </code></pre> <p>Can anyone explain why is that and how to overcome it?</p> <p>Error : </p> <pre><code>Fatal error: Allowed memory size of 134217728 b...
[ { "answer_id": 191777, "author": "Bruno Monteiro", "author_id": 36031, "author_profile": "https://wordpress.stackexchange.com/users/36031", "pm_score": 2, "selected": false, "text": "<p>Running a no limit query is very likely the cause of your memory issues. So you might want to change y...
2015/06/17
[ "https://wordpress.stackexchange.com/questions/191775", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/68403/" ]
I got a fatal error in existing code, when I debug deeper I found that it was coming from bellow line. ``` get_posts( array("posts_per_page"=>-1) ); ``` Can anyone explain why is that and how to overcome it? Error : ``` Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes) in ...
Running a no limit query is very likely the cause of your memory issues. So you might want to change your query. If still you need to do this way, you can use the `fields` option, it returns post IDs only and will save a lot of memory usage - example below: ``` $your_query = get_posts( array( 'posts_per_p...
191,779
<p>Just a few days ago I've started working on my new wordpress based website.</p> <p>I have a plugin which provides a Cars Database. I want to auto-fill my custom fields and taxonomies by taking info from this plugin.</p> <p>So, I've created a custom function in functions.php. I put an ID from car's database plugin ...
[ { "answer_id": 191782, "author": "unknowndomain", "author_id": 8490, "author_profile": "https://wordpress.stackexchange.com/users/8490", "pm_score": 2, "selected": false, "text": "<p>Implode turns your array like this <code>array( 'Audi', 'BMW', 'Mercedes-Benz' )</code> into a string sep...
2015/06/17
[ "https://wordpress.stackexchange.com/questions/191779", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74827/" ]
Just a few days ago I've started working on my new wordpress based website. I have a plugin which provides a Cars Database. I want to auto-fill my custom fields and taxonomies by taking info from this plugin. So, I've created a custom function in functions.php. I put an ID from car's database plugin and my function a...
The second parameter to [`wp_set_object_terms()`](https://codex.wordpress.org/Function_Reference/wp_set_object_terms) takes an array, integer, or string. > > (*array/int/string*) > (*required*) The slug or id of the term (such as category or tag > IDs), will replace all existing related terms in this taxonomy. To ...
191,801
<p>I always run into an issue with creating archive or landing pages for custom post types and wanted to know how others handle this.</p> <p>If I want to have a landing page for a custom post type, however I want the archive page to contain editable content (i.e. be a physical page). I will need to make a custom templ...
[ { "answer_id": 191803, "author": "s_ha_dum", "author_id": 21376, "author_profile": "https://wordpress.stackexchange.com/users/21376", "pm_score": 0, "selected": false, "text": "<p>I would...</p>\n\n<ol>\n<li>Create a CPT registered with <code>'has_archive' =&gt; false</code> and use that...
2015/06/17
[ "https://wordpress.stackexchange.com/questions/191801", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/35203/" ]
I always run into an issue with creating archive or landing pages for custom post types and wanted to know how others handle this. If I want to have a landing page for a custom post type, however I want the archive page to contain editable content (i.e. be a physical page). I will need to make a custom template for my...
For this situation, I create a custom page template, say `tpl-archive-page.php`. For example using [Advanced Custom Fields](http://www.advancedcustomfields.com/) and the [Post Type Selector Field](https://github.com/TimPerry/acf-post-type-selector)(\*) the user can choose a post type to connect to. ``` <?php /** * Te...
191,802
<p>I already created a custom post type with post-format support declared.</p> <pre><code>register_post_type('portfolio', array( 'labels' =&gt; array( 'name' =&gt; __('Portfolio', "xxx"), 'singular_name' =&gt; __('Portfolio', "xxx") ), 'public' =&gt; true, 'menu_...
[ { "answer_id": 191841, "author": "Atthapon Junpun-eak", "author_id": 28340, "author_profile": "https://wordpress.stackexchange.com/users/28340", "pm_score": 1, "selected": false, "text": "<p>After spending time debugging export.php, I found that we have to register post_format taxonomy f...
2015/06/17
[ "https://wordpress.stackexchange.com/questions/191802", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/28340/" ]
I already created a custom post type with post-format support declared. ``` register_post_type('portfolio', array( 'labels' => array( 'name' => __('Portfolio', "xxx"), 'singular_name' => __('Portfolio', "xxx") ), 'public' => true, 'menu_position' => 5, 'r...
After spending time debugging export.php, I found that we have to register post\_format taxonomy for our custom post type. ``` register_taxonomy( 'post_format', 'portfolio', array( 'public' => true, 'hierarchical' => false, 'labels' => array( 'name' => _x( 'Forma...
191,804
<p>I would like to remove all posts with a post type of <code>nf_sub</code> from showing up in any RSS feeds, including comment feeds, how can I do this?</p>
[ { "answer_id": 191807, "author": "luke", "author_id": 34790, "author_profile": "https://wordpress.stackexchange.com/users/34790", "pm_score": 1, "selected": false, "text": "<p>Paste this in your <code>functions.php</code>of the active Theme or leave it in a custom plugin. Replace <code>y...
2015/06/17
[ "https://wordpress.stackexchange.com/questions/191804", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/66435/" ]
I would like to remove all posts with a post type of `nf_sub` from showing up in any RSS feeds, including comment feeds, how can I do this?
Paste this in your `functions.php`of the active Theme or leave it in a custom plugin. Replace `your-cpt` string. ``` /** * Filter the feed, exclude specific custom post type * * @param WP_Query object $query * @return void */ function wpse_191804_pre_get_posts( $query ) { // only for feeds if( !$query->is...
191,809
<p>I have several post types "Courses", "Institutes" having same taxonomy "country". I am using this to get term on single-courses.php</p> <pre><code>&lt;?php $terms = get_the_terms( $post-&gt;ID , 'country' ); foreach ( $terms as $term ) { $term_link = get_term_link( $term, 'country' ); if( is_wp_error( $ter...
[ { "answer_id": 191810, "author": "Bruno Monteiro", "author_id": 36031, "author_profile": "https://wordpress.stackexchange.com/users/36031", "pm_score": 0, "selected": false, "text": "<p>Maybe you can try this:</p>\n\n<pre><code>&lt;?php\n$post_type = 'your_current_post_type_name';\n$tax ...
2015/06/17
[ "https://wordpress.stackexchange.com/questions/191809", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/9711/" ]
I have several post types "Courses", "Institutes" having same taxonomy "country". I am using this to get term on single-courses.php ``` <?php $terms = get_the_terms( $post->ID , 'country' ); foreach ( $terms as $term ) { $term_link = get_term_link( $term, 'country' ); if( is_wp_error( $term_link ) ) conti...
[If you look at WordPress' available query variables](https://codex.wordpress.org/WordPress_Query_Vars#Query_variables), you will notice `post_type`. You will need to add that to your URL: ``` $terms = get_the_terms( $post->ID , 'category' ); foreach ( $terms as $term ) { $term_link = get_term_link( $term, 'categor...
191,824
<p>I'm creating a plugin that adds a custom feed. I am using a <code>pre_get_posts</code> filter to change the <code>posts_per_page</code> query var to -1 (to get all items of a custom post type). However, if I dump the <code>$wp_query</code> in the render function, <code>posts_per_page</code> remains the default. I te...
[ { "answer_id": 191847, "author": "s_ha_dum", "author_id": 21376, "author_profile": "https://wordpress.stackexchange.com/users/21376", "pm_score": 2, "selected": false, "text": "<p><a href=\"https://codex.wordpress.org/Plugin_API/Action_Reference#Actions_Run_During_a_Typical_Request\" rel...
2015/06/17
[ "https://wordpress.stackexchange.com/questions/191824", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74507/" ]
I'm creating a plugin that adds a custom feed. I am using a `pre_get_posts` filter to change the `posts_per_page` query var to -1 (to get all items of a custom post type). However, if I dump the `$wp_query` in the render function, `posts_per_page` remains the default. I tested also changing `posts_per_rss` to -1, and I...
Per the discussion/help in this thread, below is the basic code that ended up working for my purposes. Setting the `posts_per_page` query var was a futile exercise since it is overwritten by the `posts_per_rss` option in a feed query (my scenario). `posts_per_rss` is not a query var and must be set a different way, thu...
191,854
<p>I have a blog in WordPress. I have multiple categories. I want to use a specific layout for all posts under a category and all of its sub categories.</p> <p><strong>Example :</strong> My categories organized as bellow.</p> <ol> <li><p>Guide(parent category)</p> <p>1.1 Electical</p> <p>1.1.1 TV</p> <p>1.1.2 Radi...
[ { "answer_id": 191857, "author": "Pieter Goosen", "author_id": 31545, "author_profile": "https://wordpress.stackexchange.com/users/31545", "pm_score": 2, "selected": false, "text": "<h2>EDIT</h2>\n\n<p><strong><em>NOTE</strong> If you need only the parent and first level child terms, the...
2015/06/18
[ "https://wordpress.stackexchange.com/questions/191854", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64976/" ]
I have a blog in WordPress. I have multiple categories. I want to use a specific layout for all posts under a category and all of its sub categories. **Example :** My categories organized as bellow. 1. Guide(parent category) 1.1 Electical 1.1.1 TV 1.1.2 Radio 1.2 Plumbing 1.3 Home Repair 1.3.1 Kitchen 1.3.2 Ba...
You can do that with `single_template` filter. First you will need to check if a post belongs to a top level category. So here is the function. ``` // custom single template for specific category function wpse_custom_category_single_template( $single_template ) { global $post; // get all categories of curren...
191,856
<p>As per my requirement I need to show a page say <code>firstpage.php</code> for user who visit my site for <code>first time</code> else should show home page say <code>homepage.php</code></p> <p>I created both this pages as <code>page-templates</code></p> <p>For this so far I have managed to set using cookies using...
[ { "answer_id": 191857, "author": "Pieter Goosen", "author_id": 31545, "author_profile": "https://wordpress.stackexchange.com/users/31545", "pm_score": 2, "selected": false, "text": "<h2>EDIT</h2>\n\n<p><strong><em>NOTE</strong> If you need only the parent and first level child terms, the...
2015/06/18
[ "https://wordpress.stackexchange.com/questions/191856", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/63278/" ]
As per my requirement I need to show a page say `firstpage.php` for user who visit my site for `first time` else should show home page say `homepage.php` I created both this pages as `page-templates` For this so far I have managed to set using cookies using below code ``` if (!isset($_COOKIE['visited'])) { // no coo...
You can do that with `single_template` filter. First you will need to check if a post belongs to a top level category. So here is the function. ``` // custom single template for specific category function wpse_custom_category_single_template( $single_template ) { global $post; // get all categories of curren...
191,864
<p>I am looking for a script to select 1 random post per day in Wordpress. I found the code below, but this keeps gathering a new post every time I refresh the page:</p> <pre><code> &lt;?php function force_random_day_seed($orderby) { $seed = floor( time() / DAY_IN_SECONDS ); $orderby=str_replace('RAND()', "RAN...
[ { "answer_id": 191868, "author": "Domain", "author_id": 26523, "author_profile": "https://wordpress.stackexchange.com/users/26523", "pm_score": 0, "selected": false, "text": "<p>Try to use following code:-</p>\n\n<pre><code> &lt;?php\n function force_random_day_seed($orderby) {\n ...
2015/06/18
[ "https://wordpress.stackexchange.com/questions/191864", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/32810/" ]
I am looking for a script to select 1 random post per day in Wordpress. I found the code below, but this keeps gathering a new post every time I refresh the page: ``` <?php function force_random_day_seed($orderby) { $seed = floor( time() / DAY_IN_SECONDS ); $orderby=str_replace('RAND()', "RAND({$seed})", $ord...
Note that the `posts_orderby` filter is not available for `get_posts()` where `suppress_filters` is `true` by default. You can use `WP_Query` instead: ``` $args = [ 'posts_per_page' => 1, 'orderby' => 'rand', 'post_type' => 'listing', 'ignore_sticky_posts' => true, ]; a...
191,877
<p><strong>UPDATE</strong>: </p> <p>The hook is working with "classic" Wordpress filter (like <code>post__in</code>), so it's probably a Posts2Posts issue. I'm still looking for suggestions if someone has any idea.</p> <p><strong>ORIGINAL POST</strong></p> <p>I'm trying to get all posts displayed by issue number in ...
[ { "answer_id": 191883, "author": "Mayeenul Islam", "author_id": 22728, "author_profile": "https://wordpress.stackexchange.com/users/22728", "pm_score": 0, "selected": false, "text": "<p>I din't try this. But what about making a function for fetching the <code>issue_id</code>? And remembe...
2015/06/18
[ "https://wordpress.stackexchange.com/questions/191877", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/38465/" ]
**UPDATE**: The hook is working with "classic" Wordpress filter (like `post__in`), so it's probably a Posts2Posts issue. I'm still looking for suggestions if someone has any idea. **ORIGINAL POST** I'm trying to get all posts displayed by issue number in archive pages. Issues are a custom post type (linked with pos...
I couldn't solve this issue but found a workaround : I get my issue ID on parse\_request hook and use it in parse\_query (I created a class with an $issue\_id var, but global variable should be fine too). Still don't know why you can't use WP\_Query directly in parse\_query, but I opened ticket on Posts2Posts github...
191,891
<p><strong>Plugin Class File:</strong></p> <pre><code>function __construct() { add_shortcode('user_registration_form', array($this, 'shortcode')); } public function hook(){ add_action( 'wp_ajax_get_product_serial_callback', 'get_product_serial_callback' ); add_action( 'wp_ajax_nopriv_g...
[ { "answer_id": 191894, "author": "Domain", "author_id": 26523, "author_profile": "https://wordpress.stackexchange.com/users/26523", "pm_score": 1, "selected": false, "text": "<p>Put below code in _construct() function and change action name to get_product_serial_callback :-</p>\n\n<pre><...
2015/06/18
[ "https://wordpress.stackexchange.com/questions/191891", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/66252/" ]
**Plugin Class File:** ``` function __construct() { add_shortcode('user_registration_form', array($this, 'shortcode')); } public function hook(){ add_action( 'wp_ajax_get_product_serial_callback', 'get_product_serial_callback' ); add_action( 'wp_ajax_nopriv_get_product_serial_callback'...
Put below code in \_construct() function and change action name to get\_product\_serial\_callback :- ``` add_action( 'wp_ajax_get_product_serial_callback', array($this,'get_product_serial_callback') ); add_action( 'wp_ajax_nopriv_get_product_serial_callback', array($this,'get_product_serial_callback' )); ```
191,896
<p>I am running into a headache trying to get some url rewriting working on a wordpress website, running Centos 6 for operating system.</p> <p>This is what I am trying to achieve.</p> <p><strong>Current URL = <a href="http://www.downer.co.uk/property-details/?propertyidtag=508362_166879S" rel="nofollow">http://www.do...
[ { "answer_id": 191894, "author": "Domain", "author_id": 26523, "author_profile": "https://wordpress.stackexchange.com/users/26523", "pm_score": 1, "selected": false, "text": "<p>Put below code in _construct() function and change action name to get_product_serial_callback :-</p>\n\n<pre><...
2015/06/18
[ "https://wordpress.stackexchange.com/questions/191896", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74877/" ]
I am running into a headache trying to get some url rewriting working on a wordpress website, running Centos 6 for operating system. This is what I am trying to achieve. **Current URL = <http://www.downer.co.uk/property-details/?propertyidtag=508362_166879S>** I would like this to be re-written to **<http://www.do...
Put below code in \_construct() function and change action name to get\_product\_serial\_callback :- ``` add_action( 'wp_ajax_get_product_serial_callback', array($this,'get_product_serial_callback') ); add_action( 'wp_ajax_nopriv_get_product_serial_callback', array($this,'get_product_serial_callback' )); ```
191,923
<h2>Summary</h2> <p>Because of a bug in WP Core, sending <a href="https://en.wikipedia.org/wiki/MIME">multipart</a> emails (html/text) with <a href="https://codex.wordpress.org/Function_Reference/wp_mail">wp_mail()</a> (to reduce chance of emails ending up in spam folders) will <em>ironically</em> result with your dom...
[ { "answer_id": 191974, "author": "bonger", "author_id": 57034, "author_profile": "https://wordpress.stackexchange.com/users/57034", "pm_score": 5, "selected": true, "text": "<p>The following version of <code>wp_mail()</code> is with the patch applied of @rmccue/@MattyRob in the ticket <...
2015/06/18
[ "https://wordpress.stackexchange.com/questions/191923", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/24875/" ]
Summary ------- Because of a bug in WP Core, sending [multipart](https://en.wikipedia.org/wiki/MIME) emails (html/text) with [wp\_mail()](https://codex.wordpress.org/Function_Reference/wp_mail) (to reduce chance of emails ending up in spam folders) will *ironically* result with your domain being blocked by Hotmail (an...
The following version of `wp_mail()` is with the patch applied of @rmccue/@MattyRob in the ticket <https://core.trac.wordpress.org/ticket/15448>, refreshed for 4.2.2, which allows `$message` to be an array containing content-type keyed alternates: ``` /** * Send mail, similar to PHP's mail * * A true return value d...
191,924
<p>I create a new page with post name is 'my-page'. I also have 2 custom query strings. So, the URL will be like:</p> <p><a href="http://domain.com/my-page/?qst1=aaa&amp;qst2=bbb" rel="nofollow">http://domain.com/my-page/?qst1=aaa&amp;qst2=bbb</a></p> <p>I want the URL like:</p> <p><a href="http://domain.com/aaa/bbb...
[ { "answer_id": 191925, "author": "KingCodeFish", "author_id": 74125, "author_profile": "https://wordpress.stackexchange.com/users/74125", "pm_score": 1, "selected": false, "text": "<p>In your .htaccess you should be able to do something like what is shown by Chris Coyier on CSS Tricks.</...
2015/06/18
[ "https://wordpress.stackexchange.com/questions/191924", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/28101/" ]
I create a new page with post name is 'my-page'. I also have 2 custom query strings. So, the URL will be like: <http://domain.com/my-page/?qst1=aaa&qst2=bbb> I want the URL like: <http://domain.com/aaa/bbb> How I can do it? How I can tell WP it is a valid URL, because WP will point to 404 page (aaa page not found).
In your .htaccess you should be able to do something like what is shown by Chris Coyier on CSS Tricks. Link to example by Chris Coyier: <https://css-tricks.com/snippets/htaccess/subdirectories-redirect-query-string/> Since you don't have .php in your URL, WordPress has most likely already created RewriteEngine rules ...
191,933
<p>I am looking for a method to get the registered metaboxes for a specific post type (or post ID) when on a separate, unrelated post type. I am working on making a custom "editing" post type for a specific client need and want the ability to load the metaboxes without having them be registered to that 'editable' type....
[ { "answer_id": 191942, "author": "Mickey", "author_id": 74899, "author_profile": "https://wordpress.stackexchange.com/users/74899", "pm_score": 0, "selected": false, "text": "<p>Create an additional metabox (checkbox, I'm thinking) that provides the option to create an 'edit' post type f...
2015/06/18
[ "https://wordpress.stackexchange.com/questions/191933", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/403/" ]
I am looking for a method to get the registered metaboxes for a specific post type (or post ID) when on a separate, unrelated post type. I am working on making a custom "editing" post type for a specific client need and want the ability to load the metaboxes without having them be registered to that 'editable' type. *...
Wrong Assumptions ----------------- **@Rarst** or **@Dan-Cameron** answers may work, but assume that when you are viewing a post type editing page, the metaboxes for the other post type are all registered. There are different case in which that won't happen: * If metaboxes are registered using [`"add_meta_boxes_{$po...
191,938
<p><strong>UPDATED QUESTION to be CLEARER</strong></p> <p>Here's my situation:</p> <ul> <li><p>Wordpress top navigation has several menu items that jump to an array of posts within a specific category. For example, if you click "necklaces" you will find yourself in the necklaces section. You can click "next" or "prev...
[ { "answer_id": 191939, "author": "s_ha_dum", "author_id": 21376, "author_profile": "https://wordpress.stackexchange.com/users/21376", "pm_score": 0, "selected": false, "text": "<p>What's the simplest way to spit out a single category as a title in an H2 tag for a post with multiple categ...
2015/06/18
[ "https://wordpress.stackexchange.com/questions/191938", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74898/" ]
**UPDATED QUESTION to be CLEARER** Here's my situation: * Wordpress top navigation has several menu items that jump to an array of posts within a specific category. For example, if you click "necklaces" you will find yourself in the necklaces section. You can click "next" or "previous" buttons and advance to the next...
In order for this to work, you will need to know from where the single post was refered from and if the referrer is a valid one. Secondly, we need to adjust pagination between single posts in order for us to pass our referrer between single posts. The problem with referrers is, they are set and controlled by user sid...
191,947
<p>I've been developing a website on wordpress for some time now and came across some issues but until now I could figure it out, not today... Yesterday I've worked some more on the website and today when I came back to do some more work the pages on my site that are part of my navigation menu didn't load properly (min...
[ { "answer_id": 191939, "author": "s_ha_dum", "author_id": 21376, "author_profile": "https://wordpress.stackexchange.com/users/21376", "pm_score": 0, "selected": false, "text": "<p>What's the simplest way to spit out a single category as a title in an H2 tag for a post with multiple categ...
2015/06/18
[ "https://wordpress.stackexchange.com/questions/191947", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74904/" ]
I've been developing a website on wordpress for some time now and came across some issues but until now I could figure it out, not today... Yesterday I've worked some more on the website and today when I came back to do some more work the pages on my site that are part of my navigation menu didn't load properly (minus ...
In order for this to work, you will need to know from where the single post was refered from and if the referrer is a valid one. Secondly, we need to adjust pagination between single posts in order for us to pass our referrer between single posts. The problem with referrers is, they are set and controlled by user sid...
191,964
<p>Let's say I've the following file in my parent theme folder: <code>'theme-folder/inc/custom.php'</code></p> <p>Then I created a child theme.</p> <p>How can I check if that file exists in the child theme, then fetch it, otherwise fetch it from the parent theme?</p> <p><code>get_template_directory()</code> always f...
[ { "answer_id": 191968, "author": "Mathew Tinsley", "author_id": 69793, "author_profile": "https://wordpress.stackexchange.com/users/69793", "pm_score": 3, "selected": true, "text": "<p><a href=\"https://codex.wordpress.org/Function_Reference/locate_template\" rel=\"nofollow\"><code>locat...
2015/06/19
[ "https://wordpress.stackexchange.com/questions/191964", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/37529/" ]
Let's say I've the following file in my parent theme folder: `'theme-folder/inc/custom.php'` Then I created a child theme. How can I check if that file exists in the child theme, then fetch it, otherwise fetch it from the parent theme? `get_template_directory()` always fetches the file from the parent theme. While ...
[`locate_template`](https://codex.wordpress.org/Function_Reference/locate_template) will attempt to find the specified file in the child theme, and fall back to the parent theme if it does not exist: ``` locate_template('inc/custom.php', true); ``` Setting the second parameter to `true` causes it to require the file...
191,988
<p>How can I add post content in meta description via <code>Title &amp; Metas</code>?</p> <p>I have seen excerpt variable <code>%%excerpt%%</code> but it will give only excerpt but I want whole content in meta description.</p> <p>Can any one help me for this because I can not found variable for content?</p> <p>Thank...
[ { "answer_id": 191989, "author": "Karun", "author_id": 63470, "author_profile": "https://wordpress.stackexchange.com/users/63470", "pm_score": 3, "selected": true, "text": "<p>Here is a safe and Yoast preferred method</p>\n\n<pre><code>add_action('wp_head','add_custom_meta_description_bo...
2015/06/19
[ "https://wordpress.stackexchange.com/questions/191988", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/38491/" ]
How can I add post content in meta description via `Title & Metas`? I have seen excerpt variable `%%excerpt%%` but it will give only excerpt but I want whole content in meta description. Can any one help me for this because I can not found variable for content? Thankns
Here is a safe and Yoast preferred method ``` add_action('wp_head','add_custom_meta_description_box'); function retrieve_var1_replacement( $var1 ) { global $post; return strip_tags($post->post_content); } function register_my_plugin_extra_replacements() { wpseo_register_var_replacement( '%%mycus...
192,044
<p>I'm trying to make a login form, but select query isn't working. Is there another syntax in WordPress and in which way is password hashed? My code is:</p> <pre><code>if ( isset( $_POST['submit'] ) ) { if ( !$_POST['username'] ) { echo "You did not complete all of the required fields"; } else { ...
[ { "answer_id": 191989, "author": "Karun", "author_id": 63470, "author_profile": "https://wordpress.stackexchange.com/users/63470", "pm_score": 3, "selected": true, "text": "<p>Here is a safe and Yoast preferred method</p>\n\n<pre><code>add_action('wp_head','add_custom_meta_description_bo...
2015/06/19
[ "https://wordpress.stackexchange.com/questions/192044", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74943/" ]
I'm trying to make a login form, but select query isn't working. Is there another syntax in WordPress and in which way is password hashed? My code is: ``` if ( isset( $_POST['submit'] ) ) { if ( !$_POST['username'] ) { echo "You did not complete all of the required fields"; } else { $username...
Here is a safe and Yoast preferred method ``` add_action('wp_head','add_custom_meta_description_box'); function retrieve_var1_replacement( $var1 ) { global $post; return strip_tags($post->post_content); } function register_my_plugin_extra_replacements() { wpseo_register_var_replacement( '%%mycus...
192,049
<p>I'd like to avoid hard coding my plugin's version at multiple places. To realize this the function <a href="https://developer.wordpress.org/reference/functions/get_plugin_data/" rel="nofollow"><code>get_plugin_data()</code></a> comes in handy. But here the fun comes to an unpleasant stop. Checking for a plugin updat...
[ { "answer_id": 192063, "author": "s_ha_dum", "author_id": 21376, "author_profile": "https://wordpress.stackexchange.com/users/21376", "pm_score": 2, "selected": false, "text": "<blockquote>\n <p>At first glance it works and I cannot see any implications but maybe\n you are aware of som...
2015/06/19
[ "https://wordpress.stackexchange.com/questions/192049", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/50373/" ]
I'd like to avoid hard coding my plugin's version at multiple places. To realize this the function [`get_plugin_data()`](https://developer.wordpress.org/reference/functions/get_plugin_data/) comes in handy. But here the fun comes to an unpleasant stop. Checking for a plugin update to execute related housekeeping for ex...
> > At first glance it works and I cannot see any implications but maybe > you are aware of some? > > > You say that you are not getting errors, which I would have expected but [it looks as though WordPress uses `require_once()`](https://core.trac.wordpress.org/browser/tags/4.2.2/src/wp-admin/includes/admin.php#L...
192,051
<p>I'm trying to hide a large amount of categories from my category widget. I've tried a few plugins but none of them seem to want to let me use the dropdown option. I looked into the widget_categories_args hook and that seems to be what I want but I can't get it to work. </p> <p>Anyways here's my code</p> <pre><c...
[ { "answer_id": 253170, "author": "Kevin", "author_id": 76841, "author_profile": "https://wordpress.stackexchange.com/users/76841", "pm_score": 4, "selected": false, "text": "<p>I know this post is pretty old, but because I came across the same issue and this post came up higher than one ...
2015/06/19
[ "https://wordpress.stackexchange.com/questions/192051", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/55351/" ]
I'm trying to hide a large amount of categories from my category widget. I've tried a few plugins but none of them seem to want to let me use the dropdown option. I looked into the widget\_categories\_args hook and that seems to be what I want but I can't get it to work. Anyways here's my code ``` function widget_ca...
I know this post is pretty old, but because I came across the same issue and this post came up higher than one with a solution, I figured I'd add this, which worked for me. Source: <http://coffeecupweb.com/how-to-exclude-or-hide-categories-from-category-widget-in-wordpress-sidebar/> ``` //Hide categories from WordPre...
192,053
<p>I have my post image thumbnails set with: </p> <pre><code> add_theme_support('post-thumbnails'); set_post_thumbnail_size(1280, 436, true); add_image_size('general-thumb', 600, 339, true); </code></pre> <p>They are resized into two columns with the following css:</p> <pre><code> max-width: 100%; heig...
[ { "answer_id": 192363, "author": "theHands", "author_id": 74366, "author_profile": "https://wordpress.stackexchange.com/users/74366", "pm_score": 2, "selected": true, "text": "<p>It sounds like your problem occurs before the image is cropped/ resized and displayed in the page - the origi...
2015/06/19
[ "https://wordpress.stackexchange.com/questions/192053", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/35549/" ]
I have my post image thumbnails set with: ``` add_theme_support('post-thumbnails'); set_post_thumbnail_size(1280, 436, true); add_image_size('general-thumb', 600, 339, true); ``` They are resized into two columns with the following css: ``` max-width: 100%; height: auto; ``` The columns they are ...
It sounds like your problem occurs before the image is cropped/ resized and displayed in the page - the original image is too small. You can require minimum dimensions for uploaded images, see: [How to Require a Minimum Image Dimension for Uploading?](https://wordpress.stackexchange.com/questions/28359/how-to-require-...
192,061
<p>I converted an old site, which used to run on a CMS called Smarty, to WordPress and am trying to make the look and feel of the site look like a proper music lyrics site.</p> <p>There don't seem to be themes dedicated to this type of content. I have tried <a href="http://www.2035themes.com/muusico/" rel="nofollow">...
[ { "answer_id": 192062, "author": "Stephen Bailey", "author_id": 74953, "author_profile": "https://wordpress.stackexchange.com/users/74953", "pm_score": 1, "selected": false, "text": "<p>The theme is using a custom post type, in this case, \"lyrics\". Converting the old posts over to it s...
2015/06/20
[ "https://wordpress.stackexchange.com/questions/192061", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/89348/" ]
I converted an old site, which used to run on a CMS called Smarty, to WordPress and am trying to make the look and feel of the site look like a proper music lyrics site. There don't seem to be themes dedicated to this type of content. I have tried [this](http://www.2035themes.com/muusico/) theme, and while it looks to...
The theme is using a custom post type, in this case, "lyrics". Converting the old posts over to it should be as simple as writing a single query to update the old posts to the new post type. The query will be something like: ``` UPDATE `wp_posts` SET post_type = "lyrics" WHERE post_type = "post"; ``` Just as an add...
192,078
<p>I am trying to delete records from my custom table but it does not delete anything.</p> <p>Here is my code:</p> <pre><code>&lt;?php global $wpdb; $retrieve_data = $wpdb-&gt;get_results( "SELECT * FROM wp_paypal" ); // some code to display here... ?&gt; &lt;form method="post" enctype="multipart/form-data"&gt; ...
[ { "answer_id": 192103, "author": "Domain", "author_id": 26523, "author_profile": "https://wordpress.stackexchange.com/users/26523", "pm_score": 3, "selected": false, "text": "<p>Try to use <code>$wpdb-&gt;prefix</code> insted of <code>$wpdb</code> in Delete query.</p>\n\n<p>Example:</p>\...
2015/06/20
[ "https://wordpress.stackexchange.com/questions/192078", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74198/" ]
I am trying to delete records from my custom table but it does not delete anything. Here is my code: ``` <?php global $wpdb; $retrieve_data = $wpdb->get_results( "SELECT * FROM wp_paypal" ); // some code to display here... ?> <form method="post" enctype="multipart/form-data"> <td><input type="submit" name="dele...
Try to use `$wpdb->prefix` insted of `$wpdb` in Delete query. Example: ``` $wpdb->query( 'DELETE FROM '.$wpdb->prefix.'paypal WHERE id = "'.$myid.'"' ); ```
192,096
<p>I'm having hard times with showing only posts which have featured images using the loop. My PHP level is basic and any help will be really useful. </p> <p>So basically this is my original code :</p> <pre><code>if( have_posts() ) { while( have_posts() ) { the_post(); get_template_part( 'inc/te...
[ { "answer_id": 192099, "author": "Pieter Goosen", "author_id": 31545, "author_profile": "https://wordpress.stackexchange.com/users/31545", "pm_score": 4, "selected": true, "text": "<p>You need to define your arguments <strong>before</strong> you pass them to <code>WP_Query</code>, not af...
2015/06/20
[ "https://wordpress.stackexchange.com/questions/192096", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74969/" ]
I'm having hard times with showing only posts which have featured images using the loop. My PHP level is basic and any help will be really useful. So basically this is my original code : ``` if( have_posts() ) { while( have_posts() ) { the_post(); get_template_part( 'inc/template-parts/content'...
You need to define your arguments **before** you pass them to `WP_Query`, not after. Also, your `meta_query` should be an array of an array, not just an array This ``` $query = new WP_Query($thumbs); $thumbs = array( 'meta_query' => array('key' => '_thumbnail_id') ); ``` should look like this ``` $thu...
192,133
<p>I am creating a multi website for an organization and I want to do is reduce the step upon account activation so when the user register for a sub site.</p> <p>When they select a custom theme, a default content, default plugin, default menu will automatically be configured or in other words, sample content and setti...
[ { "answer_id": 192099, "author": "Pieter Goosen", "author_id": 31545, "author_profile": "https://wordpress.stackexchange.com/users/31545", "pm_score": 4, "selected": true, "text": "<p>You need to define your arguments <strong>before</strong> you pass them to <code>WP_Query</code>, not af...
2015/06/20
[ "https://wordpress.stackexchange.com/questions/192133", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/44422/" ]
I am creating a multi website for an organization and I want to do is reduce the step upon account activation so when the user register for a sub site. When they select a custom theme, a default content, default plugin, default menu will automatically be configured or in other words, sample content and settings will a...
You need to define your arguments **before** you pass them to `WP_Query`, not after. Also, your `meta_query` should be an array of an array, not just an array This ``` $query = new WP_Query($thumbs); $thumbs = array( 'meta_query' => array('key' => '_thumbnail_id') ); ``` should look like this ``` $thu...
192,159
<p>Does someone know a solution for this?</p> <p>I want to remove (<strong>not unregister</strong>) all widgets from a sidebar with a function.</p>
[ { "answer_id": 192161, "author": "James Barrett", "author_id": 74733, "author_profile": "https://wordpress.stackexchange.com/users/74733", "pm_score": 4, "selected": true, "text": "<p>You could add this function to your functions.php file.</p>\n\n<pre><code>add_filter( 'sidebars_widgets'...
2015/06/21
[ "https://wordpress.stackexchange.com/questions/192159", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/33235/" ]
Does someone know a solution for this? I want to remove (**not unregister**) all widgets from a sidebar with a function.
You could add this function to your functions.php file. ``` add_filter( 'sidebars_widgets', 'disable_all_widgets' ); function disable_all_widgets( $sidebars_widgets ) { $sidebars_widgets = array( false ); return $sidebars_widgets; } ``` You could also use the [Wordpress conditional tags](http://codex.wordpres...
192,193
<p>For example I have an image that's very long but want to show a cropped version of that but when people click my blog post from the homepage they see the longer version.</p> <p>I tried doing using the plugin "Custom CSS Manager" with the code:</p> <pre><code>.home .post-4262 .entry p:first-of-type { max-height:...
[ { "answer_id": 192161, "author": "James Barrett", "author_id": 74733, "author_profile": "https://wordpress.stackexchange.com/users/74733", "pm_score": 4, "selected": true, "text": "<p>You could add this function to your functions.php file.</p>\n\n<pre><code>add_filter( 'sidebars_widgets'...
2015/06/21
[ "https://wordpress.stackexchange.com/questions/192193", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/75022/" ]
For example I have an image that's very long but want to show a cropped version of that but when people click my blog post from the homepage they see the longer version. I tried doing using the plugin "Custom CSS Manager" with the code: ``` .home .post-4262 .entry p:first-of-type { max-height: 375px; overflow: ...
You could add this function to your functions.php file. ``` add_filter( 'sidebars_widgets', 'disable_all_widgets' ); function disable_all_widgets( $sidebars_widgets ) { $sidebars_widgets = array( false ); return $sidebars_widgets; } ``` You could also use the [Wordpress conditional tags](http://codex.wordpres...
192,202
<p>i'm really getting crazy about this. after hours of trials, i can't get out of this.</p> <p>I'm trying to pass a php variable value to an enqueued jquery script but i can't. </p> <p>here is my code.</p> <p>php : </p> <pre><code>function itinerary_enqueuescripts(){ wp_enqueue_script('itenqueue', JSONURL.'/js/load...
[ { "answer_id": 192161, "author": "James Barrett", "author_id": 74733, "author_profile": "https://wordpress.stackexchange.com/users/74733", "pm_score": 4, "selected": true, "text": "<p>You could add this function to your functions.php file.</p>\n\n<pre><code>add_filter( 'sidebars_widgets'...
2015/06/22
[ "https://wordpress.stackexchange.com/questions/192202", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/51568/" ]
i'm really getting crazy about this. after hours of trials, i can't get out of this. I'm trying to pass a php variable value to an enqueued jquery script but i can't. here is my code. php : ``` function itinerary_enqueuescripts(){ wp_enqueue_script('itenqueue', JSONURL.'/js/loadjson.js', array('jquery')); wp_loca...
You could add this function to your functions.php file. ``` add_filter( 'sidebars_widgets', 'disable_all_widgets' ); function disable_all_widgets( $sidebars_widgets ) { $sidebars_widgets = array( false ); return $sidebars_widgets; } ``` You could also use the [Wordpress conditional tags](http://codex.wordpres...
192,243
<p>Is there any experience using widget logic, I want to display a widget on single custom post type with specific taxonomy. Tried using </p> <pre><code>is_tax(taxonomy_name) || is_single() &amp;&amp; in_term(term_name). </code></pre>
[ { "answer_id": 192247, "author": "Anand", "author_id": 73187, "author_profile": "https://wordpress.stackexchange.com/users/73187", "pm_score": -1, "selected": false, "text": "<p>Please try below code:</p>\n\n<pre><code>if(has_tag( array( 'sharp', 'mild', 'extreme' ) ) &amp;&amp; get_post...
2015/06/22
[ "https://wordpress.stackexchange.com/questions/192243", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/62707/" ]
Is there any experience using widget logic, I want to display a widget on single custom post type with specific taxonomy. Tried using ``` is_tax(taxonomy_name) || is_single() && in_term(term_name). ```
Before I start, I must say that your terminology is quite confusing and plain wrong. You should take your time and read through [my answer](https://wordpress.stackexchange.com/a/158223/31545) to this question: [Is There a Difference Between Taxonomies and Categories?](https://wordpress.stackexchange.com/questions/15820...
192,245
<p>I have this custom query:</p> <pre><code>query_posts( array ( 'orderby' =&gt; 'rr_recommends_count', 'meta_key' =&gt; 'rr_recommends_count', 'order' =&gt; 'DESC', ) ); </code></pre> <p>Which orders the posts like this:</p> <p>9, 8, 7, 6, 5, 4, 3, 2, <strong>11, 10,</strong> 1 etc.</p> <p>I see...
[ { "answer_id": 192248, "author": "Pieter Goosen", "author_id": 31545, "author_profile": "https://wordpress.stackexchange.com/users/31545", "pm_score": 3, "selected": true, "text": "<p>First of all, never ever use <code>query_posts</code>. It breaks the main function and all plugins and f...
2015/06/22
[ "https://wordpress.stackexchange.com/questions/192245", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/25239/" ]
I have this custom query: ``` query_posts( array ( 'orderby' => 'rr_recommends_count', 'meta_key' => 'rr_recommends_count', 'order' => 'DESC', ) ); ``` Which orders the posts like this: 9, 8, 7, 6, 5, 4, 3, 2, **11, 10,** 1 etc. I see that the problem is that the meta\_value field has a type of ...
First of all, never ever use `query_posts`. It breaks the main function and all plugins and functions relying on the main query object. For custom queries, use `WP_Query` or `get_posts` if aren't looking to paginate the query As for the following line ``` 'orderby' => 'rr_recommends_count', ``` I can tell you that ...
192,258
<p>I have to execute custom PHP code after new post is saved with all it's meta data.</p> <p>My question is how to achieve that? Tried with <strong>save_post</strong> action, but it executes before meta records are saved, so I cannot use it in this case.</p> <p>So, how can I run my custom function after post with all...
[ { "answer_id": 192323, "author": "Frank P. Walentynowicz", "author_id": 32851, "author_profile": "https://wordpress.stackexchange.com/users/32851", "pm_score": 3, "selected": false, "text": "<p>For <strong>NEW</strong> post type 'post' use <code>draft_to_publish</code> action hook:</p>\n...
2015/06/22
[ "https://wordpress.stackexchange.com/questions/192258", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/44050/" ]
I have to execute custom PHP code after new post is saved with all it's meta data. My question is how to achieve that? Tried with **save\_post** action, but it executes before meta records are saved, so I cannot use it in this case. So, how can I run my custom function after post with all related data is saved in dat...
For **NEW** post type 'post' use `draft_to_publish` action hook: ``` function fpw_post_info( $post ) { if ( 'post' == $post->post_type ) { // echo '<pre>'; print_r( $post ); echo '<br />'; // $meta = get_post_meta( $post->ID ); print_r( $meta ); echo '</pre>'; die(); // your custom code goe...
192,275
<p>I'm experiencing an odd situation while running an UPDATE with <code>$wpdb-&gt;query()</code>.</p> <p>Given the <code>users</code> table, with columns <code>user_id</code> (Primary Key) and <code>status</code>, and the user 3 existing and with status 0, I run the following query:</p> <pre> update users set status ...
[ { "answer_id": 192284, "author": "s_ha_dum", "author_id": 21376, "author_profile": "https://wordpress.stackexchange.com/users/21376", "pm_score": 1, "selected": false, "text": "<p><code>wpdb</code> <a href=\"https://core.trac.wordpress.org/browser/tags/4.2.2/src/wp-includes/wp-db.php#L16...
2015/06/22
[ "https://wordpress.stackexchange.com/questions/192275", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/69734/" ]
I'm experiencing an odd situation while running an UPDATE with `$wpdb->query()`. Given the `users` table, with columns `user_id` (Primary Key) and `status`, and the user 3 existing and with status 0, I run the following query: ``` update users set status = 8 where user_id = 3 ``` On my machine, running the query w...
`wpdb` [uses PHP's `mysqli_affected_rows()` or `mysql_affected_rows()`](https://core.trac.wordpress.org/browser/tags/4.2.2/src/wp-includes/wp-db.php#L1686), which can be disabled [via an argument in `php.ini`](http://php.net/manual/en/ini.core.php#ini.disable-functions). I am guessing that that is what has happened. Ch...
192,340
<p>Hi i would like to add a custom text in order confirmation email template . Currently i am not using woo commerce tax option, But i would like to mention my product has 25 % including vat in email template . That custom text need to show only in order confirmation email template near Order total : Total: 348.00 DK...
[ { "answer_id": 192351, "author": "Anam Shah", "author_id": 75030, "author_profile": "https://wordpress.stackexchange.com/users/75030", "pm_score": 0, "selected": false, "text": "<p>Go to your child theme folder.</p>\n\n<p>Find woccomerce > emails</p>\n\n<p>from here you can edit your ema...
2015/06/23
[ "https://wordpress.stackexchange.com/questions/192340", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74812/" ]
Hi i would like to add a custom text in order confirmation email template . Currently i am not using woo commerce tax option, But i would like to mention my product has 25 % including vat in email template . That custom text need to show only in order confirmation email template near Order total : Total: 348.00 DKK ( I...
You can add custom text or html using this action. ``` add_action( 'woocommerce_email_after_order_table', 'add_order_email_instructions', 10, 2 ); function add_order_email_instructions( $order, $sent_to_admin ) { if ( ! $sent_to_admin ) { echo 'Custom HTml OR Custom Text'; } } ```
192,341
<p>I want to add javascript to page footer if the shortcode is used into the page content.</p> <pre><code>add_shortcode('show-popup', 'show_aip_popup'); function show_aip_popup($args){ // HTML Comes here for popup } </code></pre>
[ { "answer_id": 192345, "author": "Mitul", "author_id": 74728, "author_profile": "https://wordpress.stackexchange.com/users/74728", "pm_score": 1, "selected": false, "text": "<p>Thank you for your help </p>\n\n<p>I have do some googling and finally i got the ans i have added just 1 line ...
2015/06/23
[ "https://wordpress.stackexchange.com/questions/192341", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74728/" ]
I want to add javascript to page footer if the shortcode is used into the page content. ``` add_shortcode('show-popup', 'show_aip_popup'); function show_aip_popup($args){ // HTML Comes here for popup } ```
Please try this one ``` function show_aip_popup($args){ wp_enqueue_script( 'parent-stylesheet', 'javascript file', false ); //your code for show shortcode data } ```
192,344
<p>I am using "front-end-only-users" plugin for user registration and log in system. Now how i check that my front end user is log in or not through coding i use 'is_user_logged_in()' but it checking the admin panel user.</p>
[ { "answer_id": 192347, "author": "Anam Shah", "author_id": 75030, "author_profile": "https://wordpress.stackexchange.com/users/75030", "pm_score": 1, "selected": false, "text": "<p>Hope this will helful to you</p>\n\n<pre><code>global $current_user; // Use global\nget_currentuserinfo(); ...
2015/06/23
[ "https://wordpress.stackexchange.com/questions/192344", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74808/" ]
I am using "front-end-only-users" plugin for user registration and log in system. Now how i check that my front end user is log in or not through coding i use 'is\_user\_logged\_in()' but it checking the admin panel user.
write this code in front page to check user is login or not: ``` if ( is_user_logged_in() ) { ... } ```
192,349
<p>I have five categories for a custom post type, additionally I have installed a plugin to enable upload image to each category detail, actually I can get show list of categories with details. I need to show a list like the follow structure:</p> <p>Image Category<br /> Category Name One<br /> This is the category des...
[ { "answer_id": 192347, "author": "Anam Shah", "author_id": 75030, "author_profile": "https://wordpress.stackexchange.com/users/75030", "pm_score": 1, "selected": false, "text": "<p>Hope this will helful to you</p>\n\n<pre><code>global $current_user; // Use global\nget_currentuserinfo(); ...
2015/06/23
[ "https://wordpress.stackexchange.com/questions/192349", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/75093/" ]
I have five categories for a custom post type, additionally I have installed a plugin to enable upload image to each category detail, actually I can get show list of categories with details. I need to show a list like the follow structure: Image Category Category Name One This is the category description for cat...
write this code in front page to check user is login or not: ``` if ( is_user_logged_in() ) { ... } ```
192,360
<p>I have a custom post type named <code>project</code> which has</p> <pre><code>'capability_type' =&gt; 'post' </code></pre> <p>while registering using <code>register_post_type</code>.</p> <p>In my theme files and also <code>functions.php</code> file, I have situations where I should check if the project to be edited ...
[ { "answer_id": 193106, "author": "Peyman Mohamadpour", "author_id": 75020, "author_profile": "https://wordpress.stackexchange.com/users/75020", "pm_score": 3, "selected": true, "text": "<p>using <code>map_meta_cap</code> I added <code>edit_post</code> per post cap to user</p>\n\n<pre><co...
2015/06/23
[ "https://wordpress.stackexchange.com/questions/192360", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/75020/" ]
I have a custom post type named `project` which has ``` 'capability_type' => 'post' ``` while registering using `register_post_type`. In my theme files and also `functions.php` file, I have situations where I should check if the project to be edited is authored by the user or not. So I use this: ``` if ( !current...
using `map_meta_cap` I added `edit_post` per post cap to user ``` function my_map_meta_cap( $caps, $cap, $user_id, $args ){ if ( 'edit_post' == $cap ) { $post = get_post( $args[0] ); $post_type = get_post_type_object( $post->post_type ); $caps = array(); if ( $user_id == $post->post...
192,412
<p>I have two custom fields:</p> <ul> <li><code>meta_key1</code> is boolean (<code>0</code> or <code>1</code>). </li> <li><code>meta_key2</code> is a date value - <code>20150623</code> for example.</li> </ul> <p>Not all <code>meta_key2</code> fields have an explicit value. It looks like their being treated as an empt...
[ { "answer_id": 192417, "author": "passatgt", "author_id": 8038, "author_profile": "https://wordpress.stackexchange.com/users/8038", "pm_score": 0, "selected": false, "text": "<p>Why not use <code>WP_Query()</code>? Lot simpler this way:</p>\n\n<pre><code> &lt;?php\n $args = array(\...
2015/06/23
[ "https://wordpress.stackexchange.com/questions/192412", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/65669/" ]
I have two custom fields: * `meta_key1` is boolean (`0` or `1`). * `meta_key2` is a date value - `20150623` for example. Not all `meta_key2` fields have an explicit value. It looks like their being treated as an empty string `''`. I'd like to find all posts that have a `meta_key2` (date) value that is greater than ...
One problem with the query is that the self-join with the ambiguous `WHERE` gives you a crossed dataset (which is masked by the `DISTINCT`), so it would be simpler to use `wp_post` as a base to attach the joins that precisely match the keys, eg ``` SELECT p.ID, key1.meta_value as prog_ongoing, key2.meta_value...
192,414
<pre> $sidebars = array( is_active_sidebar( 'footer-4' ), is_active_sidebar( 'footer-3' ), is_active_sidebar( 'footer-2' ), is_active_sidebar( 'footer-1' ), ); $col = 0; foreach ( $sidebars as $sidebar ) { if ( $sidebar ) { $col++; ...
[ { "answer_id": 192415, "author": "passatgt", "author_id": 8038, "author_profile": "https://wordpress.stackexchange.com/users/8038", "pm_score": 1, "selected": false, "text": "<p>Use the <code>array_filter()</code> function, which will remove every array element that has false as the valu...
2015/06/23
[ "https://wordpress.stackexchange.com/questions/192414", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/70695/" ]
``` $sidebars = array( is_active_sidebar( 'footer-4' ), is_active_sidebar( 'footer-3' ), is_active_sidebar( 'footer-2' ), is_active_sidebar( 'footer-1' ), ); $col = 0; foreach ( $sidebars as $sidebar ) { if ( $sidebar ) { $col++; ...
Use the `array_filter()` function, which will remove every array element that has false as the value. Then you can count the array length. So your example would look like this: ``` $sidebars = array( is_active_sidebar( 'footer-4' ), is_active_sidebar( 'footer-3' ), is_active_sidebar( 'footer-2...