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
219,357
<p>For a redirect in CF7, on_sent_ok: "location.replace('<a href="https://www.mywebsite.com/pageid" rel="nofollow">https://www.mywebsite.com/pageid</a>')" works well in the additional settings but I need to make my website more portable. I would like to use a function to call base_url() or home_url(). Instead of writin...
[ { "answer_id": 219359, "author": "cybmeta", "author_id": 37428, "author_profile": "https://wordpress.stackexchange.com/users/37428", "pm_score": 0, "selected": false, "text": "<p>If you need to get the URL of any type of post, including pages, you should use <a href=\"https://developer.w...
2016/03/01
[ "https://wordpress.stackexchange.com/questions/219357", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/82889/" ]
For a redirect in CF7, on\_sent\_ok: "location.replace('<https://www.mywebsite.com/pageid>')" works well in the additional settings but I need to make my website more portable. I would like to use a function to call base\_url() or home\_url(). Instead of writing out <http://www.mywebsite.com/pageid>, I would rather use...
If you need to get the URL of any type of post, including pages, you should use [`get_permalink()`](https://developer.wordpress.org/reference/functions/get_permalink/) function, which returns the canonical URL of the post/page taken care of WordPress permalink configuration. Using `home_url()` or `base_url()` to get a...
219,365
<p>I bought a wordpress theme and I am not able to display the category link and name.</p> <pre><code>&lt;div class="item-info"&gt;'; if($show_aut!='0'){ $author = get_author_posts_url( get_the_author_meta( 'ID' ) ); $html .='&lt;span class="item-author"&gt;&lt;a href="'.$author.'"title="'.get_the_author...
[ { "answer_id": 219359, "author": "cybmeta", "author_id": 37428, "author_profile": "https://wordpress.stackexchange.com/users/37428", "pm_score": 0, "selected": false, "text": "<p>If you need to get the URL of any type of post, including pages, you should use <a href=\"https://developer.w...
2016/03/01
[ "https://wordpress.stackexchange.com/questions/219365", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/89777/" ]
I bought a wordpress theme and I am not able to display the category link and name. ``` <div class="item-info">'; if($show_aut!='0'){ $author = get_author_posts_url( get_the_author_meta( 'ID' ) ); $html .='<span class="item-author"><a href="'.$author.'"title="'.get_the_author().'">'.get_the_author().'</a...
If you need to get the URL of any type of post, including pages, you should use [`get_permalink()`](https://developer.wordpress.org/reference/functions/get_permalink/) function, which returns the canonical URL of the post/page taken care of WordPress permalink configuration. Using `home_url()` or `base_url()` to get a...
219,381
<p>I'm working on a WordPress site and I use the following code to show posts in two columns on archive and category pages:</p> <pre><code>&lt;div id="post-&lt;?php the_ID(); ?&gt;" &lt;?php post_class( 0 === ++$GLOBALS['wpdb']-&gt;current_post % 2 ? 'grid col-340 fit' : 'grid col-340' ); ?&gt;&gt; </code></pre> <p>W...
[ { "answer_id": 219383, "author": "user3114253", "author_id": 76325, "author_profile": "https://wordpress.stackexchange.com/users/76325", "pm_score": -1, "selected": false, "text": "<p>use <code>get_the_ID()</code> to get the current post id </p>\n\n<pre><code>&lt;?php echo get_the_ID(); ...
2016/03/01
[ "https://wordpress.stackexchange.com/questions/219381", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/33903/" ]
I'm working on a WordPress site and I use the following code to show posts in two columns on archive and category pages: ``` <div id="post-<?php the_ID(); ?>" <?php post_class( 0 === ++$GLOBALS['wpdb']->current_post % 2 ? 'grid col-340 fit' : 'grid col-340' ); ?>> ``` With debug set to "true" I got the following not...
There are problems with this part: ``` ++$GLOBALS['wpdb']->current_post ``` There's no `current_post` property of the `wpdb` class, here you're most likely confusing the `wpdb` class with the `WP_Query` class. Also we wouldn't want in general to modify the `current_post` property of the global `WP_Query`, it coul...
219,391
<p>I wish that my 'custom post type archive page' would point to Page.</p> <p>The situations is as follows:</p> <p>I have <code>Page</code> in Wordpress with permalink <code>http://myurl.com/galleries</code>. This page shows list of posts with custom post type = <code>vmgallery</code>. I have custom logic for this pa...
[ { "answer_id": 219392, "author": "Sumit", "author_id": 32475, "author_profile": "https://wordpress.stackexchange.com/users/32475", "pm_score": 5, "selected": true, "text": "<p>You have multiple options here.</p>\n\n<p><strong>1. Define post type archive slug on post type registration</st...
2016/03/01
[ "https://wordpress.stackexchange.com/questions/219391", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/35268/" ]
I wish that my 'custom post type archive page' would point to Page. The situations is as follows: I have `Page` in Wordpress with permalink `http://myurl.com/galleries`. This page shows list of posts with custom post type = `vmgallery`. I have custom logic for this page that is working fine. From another view, this...
You have multiple options here. **1. Define post type archive slug on post type registration** By setting `'has_archive' => 'galleries'` you can define custom post type archive slug. Check [documentation](https://codex.wordpress.org/Function_Reference/register_post_type#has_archive). Then you can delete your page "ga...
219,410
<p>I'm making a website and it seems that product sku is hidden from product page. I have found how to add it to the catalog (shop) page but I need it to show inside the product page.</p> <p>So far, by altering the single-product.php, I managed to add it at the end of the page (something we do not want) or before the ...
[ { "answer_id": 219427, "author": "Joe Dooley", "author_id": 81789, "author_profile": "https://wordpress.stackexchange.com/users/81789", "pm_score": 4, "selected": true, "text": "<p>Add this to your functions.php</p>\n\n<pre><code>add_action( 'woocommerce_single_product_summary', 'dev_des...
2016/03/01
[ "https://wordpress.stackexchange.com/questions/219410", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/89804/" ]
I'm making a website and it seems that product sku is hidden from product page. I have found how to add it to the catalog (shop) page but I need it to show inside the product page. So far, by altering the single-product.php, I managed to add it at the end of the page (something we do not want) or before the title on t...
Add this to your functions.php ``` add_action( 'woocommerce_single_product_summary', 'dev_designs_show_sku', 5 ); function dev_designs_show_sku(){ global $product; echo 'SKU: ' . $product->get_sku(); } ``` This will output the product SKU below the product title. See image below. The product SKU is VERTEX-SL...
219,454
<p>I'm using a dynamic CSS file with PHP extention.</p> <pre><code>wp_enqueue_style('css', get_template_directory_uri().'/inc/css.php'); </code></pre> <p>The output:</p> <pre><code>&lt;link rel='stylesheet' id='dynamic-css' href='PATH/inc/css.php?ver=4.4.2' type='text/css' media='all' /&gt; </code></pre> <p>I'm al...
[ { "answer_id": 220596, "author": "iantsch", "author_id": 90220, "author_profile": "https://wordpress.stackexchange.com/users/90220", "pm_score": 0, "selected": false, "text": "<p>I don't know what you do in your <code>css.php</code> to handle your php cache, but i guess not much. If you ...
2016/03/02
[ "https://wordpress.stackexchange.com/questions/219454", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/62214/" ]
I'm using a dynamic CSS file with PHP extention. ``` wp_enqueue_style('css', get_template_directory_uri().'/inc/css.php'); ``` The output: ``` <link rel='stylesheet' id='dynamic-css' href='PATH/inc/css.php?ver=4.4.2' type='text/css' media='all' /> ``` I'm also using a cache plugin (WP Super Cache). My question ...
A great deal of this will depend on your server configuration, but: Will WP Super Cache cache the css.php output? --------------------------------------------- Extremely unlikely. If your file simply generates CSS from a few variables, then no. If however it bootstraps and loads WordPress, then it 'might' cache some...
219,471
<p>I have a little problem.</p> <p>This is my page structure:</p> <pre><code>Ancestor Parent Child 1 Child 2 Child 3 Child 4 </code></pre> <p>What i try to do is when i'm on Child 4 i want to show Child 2. </p> <p>And when i'm on Child 2 i want to show Parent. </p> <p>But i...
[ { "answer_id": 219482, "author": "Pieter Goosen", "author_id": 31545, "author_profile": "https://wordpress.stackexchange.com/users/31545", "pm_score": 1, "selected": true, "text": "<p>You need to look at <code>get_ancestors()</code> to get the top level parent of a page. Just a note, for...
2016/03/02
[ "https://wordpress.stackexchange.com/questions/219471", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/44597/" ]
I have a little problem. This is my page structure: ``` Ancestor Parent Child 1 Child 2 Child 3 Child 4 ``` What i try to do is when i'm on Child 4 i want to show Child 2. And when i'm on Child 2 i want to show Parent. But i can't figure out how to do this. The code that...
You need to look at `get_ancestors()` to get the top level parent of a page. Just a note, for reliability, use `get_queried_object()` (*or even better `$GLOBALS['wp_the_query']->get_queried_object()`*) to get the current post/page object on singular pages, `$post` can be quite unreliable You can try the following in y...
219,483
<p>I am adding a <code>#section</code> as a custom link to my menu, because I want to scroll to that section when I click on that link. When I'm on the home page, this works fine (the section is on the home page), but when I'm not, and I click on it nothing happens, because it treats the link as just <code>#section</co...
[ { "answer_id": 219482, "author": "Pieter Goosen", "author_id": 31545, "author_profile": "https://wordpress.stackexchange.com/users/31545", "pm_score": 1, "selected": true, "text": "<p>You need to look at <code>get_ancestors()</code> to get the top level parent of a page. Just a note, for...
2016/03/02
[ "https://wordpress.stackexchange.com/questions/219483", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/58895/" ]
I am adding a `#section` as a custom link to my menu, because I want to scroll to that section when I click on that link. When I'm on the home page, this works fine (the section is on the home page), but when I'm not, and I click on it nothing happens, because it treats the link as just `#section`. That is, when I'm o...
You need to look at `get_ancestors()` to get the top level parent of a page. Just a note, for reliability, use `get_queried_object()` (*or even better `$GLOBALS['wp_the_query']->get_queried_object()`*) to get the current post/page object on singular pages, `$post` can be quite unreliable You can try the following in y...
219,531
<p>Hi I have created two custom fields - both of them should be required, but when I fill out username and correct email, the error messages are skipped and user gets registered. If there is an error in username or email, it writes the messages correctly. Could anybody give me a helping hand?</p> <pre><code>//1. Add a...
[ { "answer_id": 219535, "author": "locomo", "author_id": 42754, "author_profile": "https://wordpress.stackexchange.com/users/42754", "pm_score": 1, "selected": false, "text": "<p>the value of the checkbox wouldn't be \"checked\" - it should equal whatever you put in the \"value\" attribut...
2016/03/02
[ "https://wordpress.stackexchange.com/questions/219531", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64771/" ]
Hi I have created two custom fields - both of them should be required, but when I fill out username and correct email, the error messages are skipped and user gets registered. If there is an error in username or email, it writes the messages correctly. Could anybody give me a helping hand? ``` //1. Add a new form elem...
I've found my answer - unfortunatelly I've forgotten to mention that I'm using **at same time the plugin New User Approve** and that's what has been causing the problem of accepting before firing errors. Finally, thanks to @locomo I have google the right thing. Answer found here: <https://wordpress.org/support/topic/r...
219,567
<p>I am try to hide the metabox fields with empty value like</p> <pre> $Product_Brennwert = get_post_meta(get_the_ID(), 'Product_Brennwert', true); if ( ! empty ( $Product_Brennwert ) ) { echo 'Brennwert '. $Product_power . ' '; } </pre> <p>now i am try to add this in my php file but no idea how to add this in t...
[ { "answer_id": 219536, "author": "Milo", "author_id": 4771, "author_profile": "https://wordpress.stackexchange.com/users/4771", "pm_score": 2, "selected": false, "text": "<p>The two overarching advantages are:</p>\n\n<ol>\n<li>You can (eventually) do all admin tasks without the admin int...
2016/03/03
[ "https://wordpress.stackexchange.com/questions/219567", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/24876/" ]
I am try to hide the metabox fields with empty value like ``` $Product_Brennwert = get_post_meta(get_the_ID(), 'Product_Brennwert', true); if ( ! empty ( $Product_Brennwert ) ) { echo 'Brennwert '. $Product_power . ' '; } ``` now i am try to add this in my php file but no idea how to add this in table can some...
At its current state, it is a badly engineered feature that do not have any real advantage for a competent developer. The basic idea, as it stands at the time this answer is written, is to expose WordPress core functionality as JSON REST API. This will enable decoupling of the WordPress "business" logic from the UI an...
219,568
<p>I would like to have 0 to 5, and "n/a" as possible values, however this code will output "n/a" when I want it to output a zero. How can I get it to output "0"?</p> <p>("n/a" is the placeholder if no value is set.)</p> <pre><code>Difficulty: &lt;?php if(get_field('difficulty')) { echo the_field('difficulty');} els...
[ { "answer_id": 219570, "author": "Pieter Goosen", "author_id": 31545, "author_profile": "https://wordpress.stackexchange.com/users/31545", "pm_score": -1, "selected": true, "text": "<p>In PHP, <code>0 == false == [] == '' == null</code>. A simple check to check if a variable or condition...
2016/03/03
[ "https://wordpress.stackexchange.com/questions/219568", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/87385/" ]
I would like to have 0 to 5, and "n/a" as possible values, however this code will output "n/a" when I want it to output a zero. How can I get it to output "0"? ("n/a" is the placeholder if no value is set.) ``` Difficulty: <?php if(get_field('difficulty')) { echo the_field('difficulty');} else { echo "n/a"; } ?> `...
In PHP, `0 == false == [] == '' == null`. A simple check to check if a variable or condition has a value will return `false` if the value is equal to 0. For `0` to return true as a valid value, you would need to make use of strict comparison by using the identical (*`===`*) operator. Just remember, if you use `===`, ...
219,583
<p>I have a custom form that allows users to make posts and also upload images with it. The images are saved in <code>wp_posts</code> as post_type = <code>attachment</code> with a <code>guid</code> to show the image.</p> <p>Now I have created a grid created with php which shows all main pictures of my posts. However, ...
[ { "answer_id": 219587, "author": "Prasad Nevase", "author_id": 62283, "author_profile": "https://wordpress.stackexchange.com/users/62283", "pm_score": 0, "selected": false, "text": "<p>I am not sure how you have implemented the image upload in custom form. If you have followed standard w...
2016/03/03
[ "https://wordpress.stackexchange.com/questions/219583", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/87968/" ]
I have a custom form that allows users to make posts and also upload images with it. The images are saved in `wp_posts` as post\_type = `attachment` with a `guid` to show the image. Now I have created a grid created with php which shows all main pictures of my posts. However, since I call the guid's of the images it l...
You can use several functions to get the URL of a image of any of the intermediate sizes created by WordPress (thumbnail, medium, large, full, or any other [custom size](https://developer.wordpress.org/reference/functions/add_image_size/)). You can use `get_the_post_thumbnail()`/`the_post_thumbnail()`: use this functi...
219,613
<p>I'm making a page for settings API using Codestar Framework, and loading fields using their <a href="http://codestarframework.com/documentation/#configuration" rel="nofollow">filterable configure</a> - <strong>question is not related to Codestar</strong>. In one of such dropdown field, I need to load all the posts f...
[ { "answer_id": 220258, "author": "Adam", "author_id": 13418, "author_profile": "https://wordpress.stackexchange.com/users/13418", "pm_score": 2, "selected": false, "text": "<p>It's worthwhile pointing out that using <code>admin_init</code> within the <code>current_screen</code> filter is...
2016/03/03
[ "https://wordpress.stackexchange.com/questions/219613", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/22728/" ]
I'm making a page for settings API using Codestar Framework, and loading fields using their [filterable configure](http://codestarframework.com/documentation/#configuration) - **question is not related to Codestar**. In one of such dropdown field, I need to load all the posts from a custom post type that are added with...
It's worthwhile pointing out that using `admin_init` within the `current_screen` filter is too late because `admin_init` has already fired. Instead do: ``` add_action('current_screen', 'current_screen_callback'); function current_screen_callback($screen) { if( is_object($screen) && $screen->id === 'top_level_cu...
219,629
<p>I'm writing a web/db application. My clients would like authentication based on whether the user is logged into WordPress.</p> <p>Assuming this application is hosted from within <code>/wordpress</code> I would like to be able to:</p> <ol> <li><p>Determine who, if anyone, is logged into WordPress</p> <p>Seems as i...
[ { "answer_id": 220258, "author": "Adam", "author_id": 13418, "author_profile": "https://wordpress.stackexchange.com/users/13418", "pm_score": 2, "selected": false, "text": "<p>It's worthwhile pointing out that using <code>admin_init</code> within the <code>current_screen</code> filter is...
2016/03/03
[ "https://wordpress.stackexchange.com/questions/219629", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/89934/" ]
I'm writing a web/db application. My clients would like authentication based on whether the user is logged into WordPress. Assuming this application is hosted from within `/wordpress` I would like to be able to: 1. Determine who, if anyone, is logged into WordPress Seems as if it should be possible via `wp_get_curre...
It's worthwhile pointing out that using `admin_init` within the `current_screen` filter is too late because `admin_init` has already fired. Instead do: ``` add_action('current_screen', 'current_screen_callback'); function current_screen_callback($screen) { if( is_object($screen) && $screen->id === 'top_level_cu...
219,643
<p>What is a best way to eliminate xmlrpc.php file from WordPress when you don't need it?</p>
[ { "answer_id": 219646, "author": "Jorin van Vilsteren", "author_id": 68062, "author_profile": "https://wordpress.stackexchange.com/users/68062", "pm_score": 3, "selected": false, "text": "<p>We are using the htaccess file to protect it from hackers.</p>\n\n<pre><code># BEGIN protect xmlr...
2016/03/03
[ "https://wordpress.stackexchange.com/questions/219643", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/88606/" ]
What is a best way to eliminate xmlrpc.php file from WordPress when you don't need it?
Since WordPress 3.5 this option (*`XML-RPC`*) is enabled by default, and the ability to turn it off from WordPress `dashboard` is gone. Add this code snippet for use in `functions.php`: ``` // Disable use XML-RPC add_filter( 'xmlrpc_enabled', '__return_false' ); // Disable X-Pingback to header add_filter( 'wp_heade...
219,658
<p>I made 2 plugins (Plugin A and plugin B/custom post type.) which some of the the module on Plugin A need to call taxonomy from PLUGIN B. Everything works fine when both plugin active, but when the Plugin B deactivate, I got this notice:</p> <blockquote> <p>Notice: Trying to get property of non-object in D:\MYWEB\...
[ { "answer_id": 219661, "author": "Howdy_McGee", "author_id": 7355, "author_profile": "https://wordpress.stackexchange.com/users/7355", "pm_score": 0, "selected": false, "text": "<p>Well, a simple solution is to check if whatever is returned is empty. Always throw in these conditionals to...
2016/03/03
[ "https://wordpress.stackexchange.com/questions/219658", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/89109/" ]
I made 2 plugins (Plugin A and plugin B/custom post type.) which some of the the module on Plugin A need to call taxonomy from PLUGIN B. Everything works fine when both plugin active, but when the Plugin B deactivate, I got this notice: > > Notice: Trying to get property of non-object in D:\MYWEB\InstantWP\_4.3.1\iwp...
You will either need to do two things * Check for an empty array **AND** a `WP_Error` object * Check if the taxonomy exists (*which `get_categories()` and `get_terms()` already does*) before your execute your code and still check for an empty array FEW NOTES TO CONSIDER --------------------- * [`get_categories()`](h...
219,686
<p>How can I get a list of all users that are in WordPress by their role or capabilities?</p> <p>For example: </p> <ul> <li>Display <code>all subscribers list</code> in WordPress.</li> <li>Display <code>all authors list</code> in WordPress.</li> <li>Display <code>all editors list</code> in WordPress.</li> </ul>
[ { "answer_id": 219687, "author": "Raja Usman Mehmood", "author_id": 75825, "author_profile": "https://wordpress.stackexchange.com/users/75825", "pm_score": 6, "selected": true, "text": "<p>There may be some different way to do that, but most proper way to do that is following.</p>\n\n<pr...
2016/03/04
[ "https://wordpress.stackexchange.com/questions/219686", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/75825/" ]
How can I get a list of all users that are in WordPress by their role or capabilities? For example: * Display `all subscribers list` in WordPress. * Display `all authors list` in WordPress. * Display `all editors list` in WordPress.
There may be some different way to do that, but most proper way to do that is following. ``` <?php $args = array( 'role' => 'Your desired role goes here.', 'orderby' => 'user_nicename', 'order' => 'ASC' ); $users = get_users( $args ); echo '<ul>'; foreach ( $users as $user ) { echo '<li>' . esc_...
219,745
<p>I've got the following error messages on the themecheck plugin in my WordPress theme. </p> <blockquote> <p>REQUIRED: The theme uses the register_taxonomy() function, which is plugin-territory functionality. <br> REQUIRED: The theme uses the register_post_type() function, which is plugin-territory functionality....
[ { "answer_id": 219687, "author": "Raja Usman Mehmood", "author_id": 75825, "author_profile": "https://wordpress.stackexchange.com/users/75825", "pm_score": 6, "selected": true, "text": "<p>There may be some different way to do that, but most proper way to do that is following.</p>\n\n<pr...
2016/03/04
[ "https://wordpress.stackexchange.com/questions/219745", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/81042/" ]
I've got the following error messages on the themecheck plugin in my WordPress theme. > > REQUIRED: The theme uses the register\_taxonomy() function, which is plugin-territory functionality. > > REQUIRED: The theme uses the register\_post\_type() function, which is plugin-territory functionality. > > WARNI...
There may be some different way to do that, but most proper way to do that is following. ``` <?php $args = array( 'role' => 'Your desired role goes here.', 'orderby' => 'user_nicename', 'order' => 'ASC' ); $users = get_users( $args ); echo '<ul>'; foreach ( $users as $user ) { echo '<li>' . esc_...
219,810
<p>I've internationalised my plugin and am now looking at how best to load the plugin's translated strings. I'm including myplugin/languages/myplugin.pot with my plugin but am not planning to distribute .po or .mo files.</p> <p><strong>My question:</strong></p> <p>Is it my job as a plugin author to use a function suc...
[ { "answer_id": 219812, "author": "cybmeta", "author_id": 37428, "author_profile": "https://wordpress.stackexchange.com/users/37428", "pm_score": 1, "selected": false, "text": "<p>You need to:</p>\n\n<ul>\n<li>Call to <code>load_plugin_textdomain()</code>. (<a href=\"https://developer.wor...
2016/03/05
[ "https://wordpress.stackexchange.com/questions/219810", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/22599/" ]
I've internationalised my plugin and am now looking at how best to load the plugin's translated strings. I'm including myplugin/languages/myplugin.pot with my plugin but am not planning to distribute .po or .mo files. **My question:** Is it my job as a plugin author to use a function such as `load_plugin_textdomain()...
**EDIT - apparently this is all wrong so please disregard.** You can use the `WP_LANG_DIR` constant to load translations from the update-safe languages directory first, and fall back to your plugin languages directory for any plugin-supplied translations. The default location is `wp-content/languages`, and users can s...
219,828
<p>Is it possible to communicate with a plugin from an outside source?</p> <p>I have an apache web server set up with wordpress running, and I would like to have automated input from a script trigger an action in a plugin.</p> <p>I thought at first I might just be able to make a plugin that listens on a socket for in...
[ { "answer_id": 219812, "author": "cybmeta", "author_id": 37428, "author_profile": "https://wordpress.stackexchange.com/users/37428", "pm_score": 1, "selected": false, "text": "<p>You need to:</p>\n\n<ul>\n<li>Call to <code>load_plugin_textdomain()</code>. (<a href=\"https://developer.wor...
2016/03/05
[ "https://wordpress.stackexchange.com/questions/219828", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/90060/" ]
Is it possible to communicate with a plugin from an outside source? I have an apache web server set up with wordpress running, and I would like to have automated input from a script trigger an action in a plugin. I thought at first I might just be able to make a plugin that listens on a socket for input and uses hook...
**EDIT - apparently this is all wrong so please disregard.** You can use the `WP_LANG_DIR` constant to load translations from the update-safe languages directory first, and fall back to your plugin languages directory for any plugin-supplied translations. The default location is `wp-content/languages`, and users can s...
219,845
<p>To display all the categories name with checkbox from custom taxonomy called <code>ct_category</code> I have the following code: </p> <pre><code>$terms = get_terms('ct_category'); foreach ( $terms as $term ) { echo '&lt;li class='.$term-&gt;term_id.'&gt;&lt;label &gt; &lt;input class="taxonomy_category" type="check...
[ { "answer_id": 219848, "author": "willrich33", "author_id": 90020, "author_profile": "https://wordpress.stackexchange.com/users/90020", "pm_score": 0, "selected": false, "text": "<p>It is an advanced question that would take me time to debug. However I believe the 'id' value for 'field' ...
2016/03/06
[ "https://wordpress.stackexchange.com/questions/219845", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/48090/" ]
To display all the categories name with checkbox from custom taxonomy called `ct_category` I have the following code: ``` $terms = get_terms('ct_category'); foreach ( $terms as $term ) { echo '<li class='.$term->term_id.'><label > <input class="taxonomy_category" type="checkbox" name="taxonomy_category['.$term->term_...
If `$taxonomy_category` is already an array, then: ``` 'terms' => array($taxonomy_category) ``` should just be: ``` 'terms' => $taxonomy_category ``` where `$taxonomy_category` is equal to whatever was submitted from your form as `$_POST['taxonomy_category']` or `$_GET['taxonomy_category']`
219,867
<p>I have a setup, where I want to achieve that I have a big Picture of a product (Post-image), and then below a list of other thumbnails, which can be opened in a Lightbox. I made this, by querying the post-image in the appropriate large size, and then querying the attachment images through a WP_Query post-type. But, ...
[ { "answer_id": 219848, "author": "willrich33", "author_id": 90020, "author_profile": "https://wordpress.stackexchange.com/users/90020", "pm_score": 0, "selected": false, "text": "<p>It is an advanced question that would take me time to debug. However I believe the 'id' value for 'field' ...
2016/03/06
[ "https://wordpress.stackexchange.com/questions/219867", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/80726/" ]
I have a setup, where I want to achieve that I have a big Picture of a product (Post-image), and then below a list of other thumbnails, which can be opened in a Lightbox. I made this, by querying the post-image in the appropriate large size, and then querying the attachment images through a WP\_Query post-type. But, th...
If `$taxonomy_category` is already an array, then: ``` 'terms' => array($taxonomy_category) ``` should just be: ``` 'terms' => $taxonomy_category ``` where `$taxonomy_category` is equal to whatever was submitted from your form as `$_POST['taxonomy_category']` or `$_GET['taxonomy_category']`
219,870
<p>I am working on the data validation side of my WordPress theme. I have an option where user can input JS in the backend, and same is outputted in the front end between the script tags.</p> <p>The problem I am facing is, I am not able to find a WordPress function that allows only JavaScript to pass through. What if ...
[ { "answer_id": 219881, "author": "thebigtine", "author_id": 76059, "author_profile": "https://wordpress.stackexchange.com/users/76059", "pm_score": 1, "selected": false, "text": "<p>From this answer: <a href=\"https://wordpress.stackexchange.com/a/107558/76059\">https://wordpress.stackex...
2016/03/06
[ "https://wordpress.stackexchange.com/questions/219870", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/63853/" ]
I am working on the data validation side of my WordPress theme. I have an option where user can input JS in the backend, and same is outputted in the front end between the script tags. The problem I am facing is, I am not able to find a WordPress function that allows only JavaScript to pass through. What if user types...
What you're asking for is impossible, there is no such thing as a safe javascript entry box. Even if we strip out extra script and style tags, it's pointless, as the javascript code itself is inherently dangerous, and can create any elements it wants using DOM construction, e.g.: ``` var s = jQuery( 'script', { 'src'...
219,874
<p>My WordPress plugin uses Chosen Select and is supposed to use the css file at <code>my-plugin/assets/resources/chosen.min.css</code>.</p> <p>Unfortunately, when another plugin also uses Chosen Select, my plugin has a tendency to grab styles from the other css file instead. </p> <p>For example, it's currently getti...
[ { "answer_id": 219880, "author": "Pieter Goosen", "author_id": 31545, "author_profile": "https://wordpress.stackexchange.com/users/31545", "pm_score": 3, "selected": true, "text": "<p>There really is no foolproof method to detect a style sheet from other plugins or from a theme and then ...
2016/03/06
[ "https://wordpress.stackexchange.com/questions/219874", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/81557/" ]
My WordPress plugin uses Chosen Select and is supposed to use the css file at `my-plugin/assets/resources/chosen.min.css`. Unfortunately, when another plugin also uses Chosen Select, my plugin has a tendency to grab styles from the other css file instead. For example, it's currently getting styles from `yith-woocomm...
There really is no foolproof method to detect a style sheet from other plugins or from a theme and then "switching them off". You can only guess that other plugins and themes will be using the same handle as you to register the style sheet with. It is however much easier if your plugin is for personal use only, then yo...
219,911
<p>I'm developing my first plugin and wp_enqueue_style doesn't work. I'm in localhost (apache2) installation, ubuntu 14.04.</p> <p>In my main file I have</p> <pre><code>define( 'EASYDM_CSS_DIR', plugin_dir_path( __FILE__ ).'css/' ); add_action( 'wp_enqueue_style', 'easydm_add_link_tag_to_head' ); </code></pre> <p>An...
[ { "answer_id": 219914, "author": "Tim Malone", "author_id": 46066, "author_profile": "https://wordpress.stackexchange.com/users/46066", "pm_score": 1, "selected": false, "text": "<p>You've given <code>wp_enqueue_style</code> a directory, but no file name. Have a look at <a href=\"https:/...
2016/03/07
[ "https://wordpress.stackexchange.com/questions/219911", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/89766/" ]
I'm developing my first plugin and wp\_enqueue\_style doesn't work. I'm in localhost (apache2) installation, ubuntu 14.04. In my main file I have ``` define( 'EASYDM_CSS_DIR', plugin_dir_path( __FILE__ ).'css/' ); add_action( 'wp_enqueue_style', 'easydm_add_link_tag_to_head' ); ``` And in my php functions file I ha...
You've given `wp_enqueue_style` a directory, but no file name. Have a look at <https://developer.wordpress.org/reference/functions/wp_enqueue_style/>: * The first parameter of `wp_enqueue_style` is the name, or handle, of the stylesheet as referred to internally by Wordpress (this should be a unique name for each styl...
219,931
<p>I am using the Wordpress theme Twenty Twelve (a child of it to be precise). </p> <p>I want to know how to insert some HTML just after body opening, in just functions.php and not using header.php. </p> <p>Is that possible?</p>
[ { "answer_id": 219938, "author": "Adam", "author_id": 13418, "author_profile": "https://wordpress.stackexchange.com/users/13418", "pm_score": 6, "selected": true, "text": "<p>Twenty Twelve does not have any hooks that fire immediately after the opening <code>&lt;body&gt;</code> tag.</p>\...
2016/03/07
[ "https://wordpress.stackexchange.com/questions/219931", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/87509/" ]
I am using the Wordpress theme Twenty Twelve (a child of it to be precise). I want to know how to insert some HTML just after body opening, in just functions.php and not using header.php. Is that possible?
Twenty Twelve does not have any hooks that fire immediately after the opening `<body>` tag. Therefore you in your child theme which extends the parent Twenty Twelve theme, copy the `header.php` across to your child theme directory. Open the `header.php` file in your child theme and just after the opening body tag add...
219,954
<p>My loop below shows the latest 4 posts from the same category as the post currently being viewed. Its located within single.php. </p> <p>I'm trying to get the URL of that same category so I can link back to category.php to view all posts from that same category. I thought grabbing the category slug would work but m...
[ { "answer_id": 219955, "author": "Adam", "author_id": 13418, "author_profile": "https://wordpress.stackexchange.com/users/13418", "pm_score": 4, "selected": true, "text": "<p>Use:</p>\n\n<pre><code>get_category_link( $category_id );\n</code></pre>\n\n<p>See: </p>\n\n<p><a href=\"https://...
2016/03/07
[ "https://wordpress.stackexchange.com/questions/219954", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/14149/" ]
My loop below shows the latest 4 posts from the same category as the post currently being viewed. Its located within single.php. I'm trying to get the URL of that same category so I can link back to category.php to view all posts from that same category. I thought grabbing the category slug would work but my code bel...
Use: ``` get_category_link( $category_id ); ``` See: <https://codex.wordpress.org/Function_Reference/get_category_link> In your specific case: ``` <?php global $post; $categories = get_the_category(); foreach ($categories as $category) : $exclude = get_the_ID(); $posts = get_posts('posts_per_...
219,959
<p>I want to restrict pending posts to only certain users in the admin section, so I want to remove it from the post status options when viewing all posts (the bit highlighted in red in the image below):</p> <p><a href="https://i.stack.imgur.com/XHX9j.png" rel="noreferrer"><img src="https://i.stack.imgur.com/XHX9j.png...
[ { "answer_id": 219961, "author": "Adam", "author_id": 13418, "author_profile": "https://wordpress.stackexchange.com/users/13418", "pm_score": 2, "selected": false, "text": "<p>The filter you are looking for is <code>views_{$this-&gt;screen-&gt;id}</code> which is located in the <code>WP_...
2016/03/07
[ "https://wordpress.stackexchange.com/questions/219959", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/63673/" ]
I want to restrict pending posts to only certain users in the admin section, so I want to remove it from the post status options when viewing all posts (the bit highlighted in red in the image below): [![WordPress post statuses submenu](https://i.stack.imgur.com/XHX9j.png)](https://i.stack.imgur.com/XHX9j.png) Howeve...
The filter you are looking for is `views_{$this->screen->id}` which is located in the `WP_List_Table::views()` method. Where `$this->screen->id` is that of the context you are in, e.g. `posts`, `users`, etc... File `wp-admin/class-wp-list-table.php` Example usage: ``` function filter_posts_listable_views($views) { ...
219,974
<p>I have declared post type as below:</p> <pre><code> $args = array( 'labels' =&gt; $labels, 'public' =&gt; true, 'publicly_queryable' =&gt; true, 'show_ui' =&gt; true, 'show_in_menu' =&gt; true, 'query_var' =&gt; true, 'rewrite' =&gt; array('slug' =&gt; 'agence...
[ { "answer_id": 219980, "author": "Mayeenul Islam", "author_id": 22728, "author_profile": "https://wordpress.stackexchange.com/users/22728", "pm_score": 4, "selected": false, "text": "<p>Newly registered CPT shows 404 because, the <code>register_post_type()</code> doesn't flush the rewrit...
2016/03/07
[ "https://wordpress.stackexchange.com/questions/219974", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/66318/" ]
I have declared post type as below: ``` $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => array('slug' => 'agences'), 'capability_type' => 'pos...
It was due to a plugin "Remove taxonomy base slug". It was conflicting with base slug of CPT "destinations". I had to use `add_rewrite_rule` to check for slug and manually redirect it to proper location
219,975
<p>I have a WordPress database with over 2 million posts. Whenever I insert a new post I have to call <code>wp_set_object_terms</code> which takes over two seconds to execute. I came across <a href="http://www.kellbot.com/wordpress-post-inserts-are-super-slow/" rel="nofollow">this post</a> that recommends calling <code...
[ { "answer_id": 219977, "author": "phatskat", "author_id": 20143, "author_profile": "https://wordpress.stackexchange.com/users/20143", "pm_score": 0, "selected": false, "text": "<p>This should be relatively safe as an operation. This is deferring the counting of terms that appears on the ...
2016/03/07
[ "https://wordpress.stackexchange.com/questions/219975", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/657/" ]
I have a WordPress database with over 2 million posts. Whenever I insert a new post I have to call `wp_set_object_terms` which takes over two seconds to execute. I came across [this post](http://www.kellbot.com/wordpress-post-inserts-are-super-slow/) that recommends calling `wp_defer_term_counting` to skip the term cou...
**Here are some thoughts on the issue, but please note that this is by no means a conclusive answer as there may be some things I have overlooked however this should give you an insight to the potential gotchas.** --- Yes, technically there could be consequences. Where calling `wp_defer_term_counting(true)` becomes ...
219,983
<p>I need help. Thanks in advance. I need a function that update post title and slug with some default title + current date when post status is updated from draft to published.</p> <p>I use this one to update the post date on status change but I need to add a functionality the title also to be updated (with a default ...
[ { "answer_id": 219992, "author": "Grandeto", "author_id": 90139, "author_profile": "https://wordpress.stackexchange.com/users/90139", "pm_score": 1, "selected": false, "text": "<p>I think I found the solution:</p>\n\n<pre><code> add_filter('wp_insert_post_data','reset_post_date',99,2);\n...
2016/03/07
[ "https://wordpress.stackexchange.com/questions/219983", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/90139/" ]
I need help. Thanks in advance. I need a function that update post title and slug with some default title + current date when post status is updated from draft to published. I use this one to update the post date on status change but I need to add a functionality the title also to be updated (with a default one) plus ...
I think I found the solution: ``` add_filter('wp_insert_post_data','reset_post_date',99,2); function reset_post_date($data,$postarr) { //update post time on status change $data['post_date'] = $data['post_modified']; $data['post_date_gmt'] = $data['post_modified_gmt']; //also update title a...
219,998
<p>I have a script I'd like to include with Wordpress. This script relies on another (prettyPhoto) to run, as well as on JQuery being loaded. I'd like my script to be the very last script to be included on the page.</p> <p>After reading about using wp_enqueue_scipt in this answer: <a href="https://stackoverflow.com/a/...
[ { "answer_id": 220001, "author": "fostertime", "author_id": 90145, "author_profile": "https://wordpress.stackexchange.com/users/90145", "pm_score": 0, "selected": false, "text": "<p>I would have simply commented on your post first, but I don't have enough reputation... :/</p>\n\n<p>Are a...
2016/03/07
[ "https://wordpress.stackexchange.com/questions/219998", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/90152/" ]
I have a script I'd like to include with Wordpress. This script relies on another (prettyPhoto) to run, as well as on JQuery being loaded. I'd like my script to be the very last script to be included on the page. After reading about using wp\_enqueue\_scipt in this answer: <https://stackoverflow.com/a/19914138/1745715...
After doing some reading, I found that it is not possible to overwrite one function in a JS file in that way. The solution was to overwrite the entire main.js file in order to make the change. I then enqueued my new main.js script with the exact same name that it was registered to in the original: ``` // Enqueue main ...
220,003
<p>I'm running a website that uses EasyAdmin (for user content generation).</p> <p>I created two taxonomies (via functions.php) for my own needs, but now my users can see them when they are adding their content to the website.</p> <pre><code>add_action( 'init', 'create_item_nominations' ); function create_item_nomin...
[ { "answer_id": 220022, "author": "Tim Malone", "author_id": 46066, "author_profile": "https://wordpress.stackexchange.com/users/46066", "pm_score": 1, "selected": false, "text": "<p>Sounds like just setting <code>show_ui</code> to <code>false</code> will do what you're after - it will hi...
2016/03/07
[ "https://wordpress.stackexchange.com/questions/220003", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/90155/" ]
I'm running a website that uses EasyAdmin (for user content generation). I created two taxonomies (via functions.php) for my own needs, but now my users can see them when they are adding their content to the website. ``` add_action( 'init', 'create_item_nominations' ); function create_item_nominations() { register...
Sounds like just setting `show_ui` to `false` will do what you're after - it will hide the taxonomy in the admin menu, and it won't create a metabox on the post edit page. After this: `'hierarchical' => true,` Add this: `'show_ui' => false,` You'll find a full reference of all the available arguments over at the W...
220,004
<p>Basically what I am trying to achieve is to have title changed of posts which are in category number 30.</p> <p>My code is:</p> <pre><code>function adddd($title) { if(has_category('30',$post-&gt;ID)){ $title = 'Prefix '.$title; } return $title; } add_action('the_title','adddd'); </code></pre> <p>The code works,...
[ { "answer_id": 220005, "author": "nicogaldo", "author_id": 87880, "author_profile": "https://wordpress.stackexchange.com/users/87880", "pm_score": 0, "selected": false, "text": "<p>Why not use javascript/jquery?</p>\n<p>if your use <code>&lt;?php post_class(); ?&gt;</code> you can find a...
2016/03/07
[ "https://wordpress.stackexchange.com/questions/220004", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/66106/" ]
Basically what I am trying to achieve is to have title changed of posts which are in category number 30. My code is: ``` function adddd($title) { if(has_category('30',$post->ID)){ $title = 'Prefix '.$title; } return $title; } add_action('the_title','adddd'); ``` The code works, but has one issue. When I am inside...
`$post` is undefined in your filter. You need to explicitely invoke the `$post` global inside your filter function to have it available. You must remember that variables (*even global variables*) outside a function will not be available inside a function, that is how PHP works. You actually do not need to use the `$po...
220,014
<p>My <code>WP_Query</code> request looks like:</p> <pre><code>$query_args = array('posts_per_page' =&gt; $products, 'no_found_rows' =&gt; 1, 'post_status' =&gt; 'publish', 'post_type' =&gt; 'product' ); $query_args['meta_query'] = $woocommerce-&gt;query-&gt;get_meta_query(); $query_args['meta_query'][] = array( '...
[ { "answer_id": 220023, "author": "Tim Malone", "author_id": 46066, "author_profile": "https://wordpress.stackexchange.com/users/46066", "pm_score": 0, "selected": false, "text": "<p>You can order in ascending or descending order, but you can't specify a custom order - in the query parame...
2016/03/07
[ "https://wordpress.stackexchange.com/questions/220014", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/28491/" ]
My `WP_Query` request looks like: ``` $query_args = array('posts_per_page' => $products, 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product' ); $query_args['meta_query'] = $woocommerce->query->get_meta_query(); $query_args['meta_query'][] = array( 'key' => '_featured', 'value' => 'yes' )...
To keep the same post order as it was passed to the `post__in` parameter, you need to pass `post__in` as value to `orderby` argument and `ASC` to the `order` argument ``` $query_args = [ 'posts_per_page' => $products, 'no_found_rows' => true, 'post_type' => 'product', 'post__in' => [161,...
220,021
<p>It took me great time today to convert one site from <a href="https://example.com" rel="nofollow">https://example.com</a> to <a href="https://sub.example2.com" rel="nofollow">https://sub.example2.com</a> from WordPress multiste installation to normal WordPress installation (read: singlesite). </p> <p>Since I starte...
[ { "answer_id": 225620, "author": "AntonChanning", "author_id": 5077, "author_profile": "https://wordpress.stackexchange.com/users/5077", "pm_score": 1, "selected": false, "text": "<p>If your multi-site install only has a small number of subsites, you might find it easier to just use the ...
2016/03/08
[ "https://wordpress.stackexchange.com/questions/220021", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/88606/" ]
It took me great time today to convert one site from <https://example.com> to <https://sub.example2.com> from WordPress multiste installation to normal WordPress installation (read: singlesite). Since I started using wp-cli recently I thought it will be possible to do it only with wp-cli. I used wp-cli to export a d...
Try using the `10up/MU-Migration` command: <https://github.com/10up/MU-Migration>
220,029
<p>I want to display a product with a product image and when visitor hovers over that image, it will change to the first image from the product gallery. I am using this code to display the image gallery, but it displays all the images from product gallery. I just want the 1 image.</p> <pre><code> &lt;?php do_action( ...
[ { "answer_id": 220036, "author": "Isaac Lubow", "author_id": 2150, "author_profile": "https://wordpress.stackexchange.com/users/2150", "pm_score": 3, "selected": true, "text": "<p>Along with the product thumbnail (I'm assuming you have this), what you need is a list (array) of the produc...
2016/03/08
[ "https://wordpress.stackexchange.com/questions/220029", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/89109/" ]
I want to display a product with a product image and when visitor hovers over that image, it will change to the first image from the product gallery. I am using this code to display the image gallery, but it displays all the images from product gallery. I just want the 1 image. ``` <?php do_action( 'woocommerce_prod...
Along with the product thumbnail (I'm assuming you have this), what you need is a list (array) of the product images - WooCommerce has such methods, eg `$product->get_gallery_attachment_ids()`. You can grab the first ID in the array and use it to fetch the single image using [`wp_get_attachment_image()`](https://devel...
220,059
<p>A WordPress website is created and MySQL is the database for it. When tried to import the database to an empty database via Linux Command Shell we encountered below errors:</p> <blockquote> <p>ERROR 1146 (42S02): Table 'xx-xxx-xxx-xxx' doesn't exist</p> <p>ERROR 1273 (HY000): Unknown collation: 'utf8mb4_unic...
[ { "answer_id": 220061, "author": "cybmeta", "author_id": 37428, "author_profile": "https://wordpress.stackexchange.com/users/37428", "pm_score": 2, "selected": false, "text": "<p>When exporting from original database you should choose to create the tables if they dosn't exist (First erro...
2016/03/08
[ "https://wordpress.stackexchange.com/questions/220059", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/75992/" ]
A WordPress website is created and MySQL is the database for it. When tried to import the database to an empty database via Linux Command Shell we encountered below errors: > > ERROR 1146 (42S02): Table 'xx-xxx-xxx-xxx' doesn't exist > > > ERROR 1273 (HY000): Unknown collation: 'utf8mb4\_unicode\_ci' > > > ERROR ...
When exporting from original database you should choose to create the tables if they dosn't exist (First error). If you didn't choose that option (in phpMyAdmin that option exists, not sure in other database tools), the import file can not create the tables for your and you need to create then prior to start importing ...
220,073
<p>While looking for proper form submission handling in plugins for users (frontend) I've stumbled upon this article <a href="http://www.sitepoint.com/handling-post-requests-the-wordpress-way/">Handling POST Requests the WordPress Way</a>, which encourages to use <code>admin-post.php</code> for this purpose. Taking a l...
[ { "answer_id": 220074, "author": "majick", "author_id": 76440, "author_profile": "https://wordpress.stackexchange.com/users/76440", "pm_score": 2, "selected": false, "text": "<p>Seems fairly clear from the use of the <code>nopriv</code> handling (for non logged in users) in <code>admin-p...
2016/03/08
[ "https://wordpress.stackexchange.com/questions/220073", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/89088/" ]
While looking for proper form submission handling in plugins for users (frontend) I've stumbled upon this article [Handling POST Requests the WordPress Way](http://www.sitepoint.com/handling-post-requests-the-wordpress-way/), which encourages to use `admin-post.php` for this purpose. Taking a look into header we can fi...
`admin-post.php` is like a poor mans controller for handling requests. It's useful in the sense that you don't need to process your request on an alternative hook such as `init` and check to see whether or not special keys exists on the superglobals, like: ``` function handle_request() { if ( !empty($_POST['acti...
220,079
<p>I use this function to insert at the beginning of the loop two post at my convenience (with meta key and value) </p> <pre><code>add_filter( 'posts_results', 'insert_post_wpse_96347', 10, 2 ); function insert_post_wpse_96347( $posts, \WP_Query $q ) { remove_filter( current_filter(), __FUNCTION__ ); if ( $q-...
[ { "answer_id": 220094, "author": "Adam", "author_id": 13418, "author_profile": "https://wordpress.stackexchange.com/users/13418", "pm_score": 0, "selected": false, "text": "<p>Try this instead:</p>\n\n<p><strong>NOTE: make sure to add any extra conditional logic you need for your usecase...
2016/03/08
[ "https://wordpress.stackexchange.com/questions/220079", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/87880/" ]
I use this function to insert at the beginning of the loop two post at my convenience (with meta key and value) ``` add_filter( 'posts_results', 'insert_post_wpse_96347', 10, 2 ); function insert_post_wpse_96347( $posts, \WP_Query $q ) { remove_filter( current_filter(), __FUNCTION__ ); if ( $q->is_main_query...
We can try the following alternative way: * Remove the two posts we select via our custom query from the main query via the `pre_get_posts` action * Return the two posts on top of page one via the `the_posts` filter Lets look at possible code: ``` add_action( 'pre_get_posts', function ( $q ) { remove_filter( cur...
220,082
<p>For each post, I use the custom excerpt field to write a custom excerpt (180 characters max) for each of my posts, which I use as the meta description of my post for SEO.</p> <p>When I show a list of my posts (archive pages, categories etc.) this excerpt is displayed as "teaser text" for each of my posts. The probl...
[ { "answer_id": 220098, "author": "thebigtine", "author_id": 76059, "author_profile": "https://wordpress.stackexchange.com/users/76059", "pm_score": 1, "selected": false, "text": "<p>This is a function that I use all the time to create a custom excerpt:</p>\n\n<pre><code>function custom_e...
2016/03/08
[ "https://wordpress.stackexchange.com/questions/220082", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/80031/" ]
For each post, I use the custom excerpt field to write a custom excerpt (180 characters max) for each of my posts, which I use as the meta description of my post for SEO. When I show a list of my posts (archive pages, categories etc.) this excerpt is displayed as "teaser text" for each of my posts. The problem is that...
We can try to filter the excerpt through the [`get_the_excerpt`](https://developer.wordpress.org/reference/hooks/get_the_excerpt/) filter. By default, if we have a manual excerpt, the manual excerpt will be used and not the automatically created excerpt which is created by the [`wp_trim_excerpt()`](https://developer.wo...
220,111
<p>I want to pass a variable from my child theme function to a filter which resides in my parent theme. Please let me know whether below code will work or not ? Is it the right way ?</p> <p><strong>Code in Parent Theme's functions.php</strong></p> <pre><code>add_filter( 'post_thumbnail_html', "map_thumbnail" ); funct...
[ { "answer_id": 220113, "author": "Brent", "author_id": 10972, "author_profile": "https://wordpress.stackexchange.com/users/10972", "pm_score": 1, "selected": false, "text": "<p>I'm not exactly sure what you're trying to accomplish but this won't work because your trying to use or call th...
2016/03/08
[ "https://wordpress.stackexchange.com/questions/220111", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/81686/" ]
I want to pass a variable from my child theme function to a filter which resides in my parent theme. Please let me know whether below code will work or not ? Is it the right way ? **Code in Parent Theme's functions.php** ``` add_filter( 'post_thumbnail_html', "map_thumbnail" ); function map_thumbnail($html,$color) { ...
I'm not exactly sure what you're trying to accomplish but this won't work because your trying to use or call the function that is declared in the parent theme instead of replacing it with a new function. I'm not sure if replacing a function in the child theme would work either. Maybe someone else can help answer that. ...
220,122
<p>I have just had to deal with a few of my WordPress websites being hacked. First time put an index.html file in the cpanel of each site and replenished my admin user. Once I felt I cleaned this up, it's happened once again but it changed my title tag to "Hacked by Bala Sniper" and the widgets from the footer of each ...
[ { "answer_id": 224778, "author": "dExIT", "author_id": 92983, "author_profile": "https://wordpress.stackexchange.com/users/92983", "pm_score": 1, "selected": false, "text": "<p>I wanted to state, this happened to me a few times in the early WP 3.x days.\nAm using GoDaddy shared hsoting e...
2016/03/08
[ "https://wordpress.stackexchange.com/questions/220122", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/86831/" ]
I have just had to deal with a few of my WordPress websites being hacked. First time put an index.html file in the cpanel of each site and replenished my admin user. Once I felt I cleaned this up, it's happened once again but it changed my title tag to "Hacked by Bala Sniper" and the widgets from the footer of each web...
*wordpress configuration file is located in the root*.In the event that PHP stops functioning on webserver for any reason.we run the risk of this file being displayed in plaintext,which will give our password and database information to visitor. you can safely move **wp-config** directory up out of root directory.this...
220,163
<p>I need to cross reference two taxonomies, <code>product_categories</code> and <code>brands</code>. the only way I can think to do this is to get all the posts in one taxonomy, then get all the posts that exist in another taxonomy:</p> <pre><code>&lt;?php $category = /* Taxonomy object selected from list */; /...
[ { "answer_id": 220213, "author": "Sumit", "author_id": 32475, "author_profile": "https://wordpress.stackexchange.com/users/32475", "pm_score": 0, "selected": false, "text": "<p>I am not so good with SQL. But this query does the job for me, I just combined two queries into one!</p>\n\n<pr...
2016/03/09
[ "https://wordpress.stackexchange.com/questions/220163", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/27504/" ]
I need to cross reference two taxonomies, `product_categories` and `brands`. the only way I can think to do this is to get all the posts in one taxonomy, then get all the posts that exist in another taxonomy: ``` <?php $category = /* Taxonomy object selected from list */; // Get all the posts in this query $ar...
We can do quite a lot to improve performance of your code. Lets set some benchmarks first BENCH MARKS ----------- * I'm testing this with a + `category` taxonomy term which has 9 posts and + the `post_tag` taxonomy with 61 matching tags. With your current code, I get the following results * ***69 queries in =/-...
220,181
<p>I want to pass my google map custom colors from my child theme to my parent theme. </p> <p><strong>So in my Parent Theme's functions.php I have</strong></p> <pre><code>add_filter( 'post_thumbnail_html', "map_thumbnail" ); function map_thumbnail($html, $color1, $color2) { $my_post = get_post($post-&gt;ID); ...
[ { "answer_id": 220183, "author": "tillinberlin", "author_id": 26059, "author_profile": "https://wordpress.stackexchange.com/users/26059", "pm_score": 0, "selected": false, "text": "<p>Without having tried it myself I would suggest you write a small function for your child theme and then ...
2016/03/09
[ "https://wordpress.stackexchange.com/questions/220181", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/81686/" ]
I want to pass my google map custom colors from my child theme to my parent theme. **So in my Parent Theme's functions.php I have** ``` add_filter( 'post_thumbnail_html', "map_thumbnail" ); function map_thumbnail($html, $color1, $color2) { $my_post = get_post($post->ID); $water_color=$color1; $t...
Stick to filtering one value at a time to keep it simple, and add filters for the colors to be used by the child theme: ``` add_filter( 'post_thumbnail_html', 'map_thumbnail'); function map_thumbnail($html) { $my_post = get_post($post->ID); $defaultcolor1 = "#??????"; // parent theme default $defaultcolor2 = ...
220,208
<p>I've applied the following code to enable the comment section in the page template.</p> <pre><code>&lt;div class="col-md-12"&gt; &lt;?php while ( have_posts() ) : the_post(); ?&gt; &lt;article id="post-&lt;?php the_ID(); ?&gt;" &lt;?php post_class(); ?&gt;&gt; ...
[ { "answer_id": 220210, "author": "Chandan Kumar Thakur", "author_id": 88637, "author_profile": "https://wordpress.stackexchange.com/users/88637", "pm_score": 0, "selected": false, "text": "<p>yes you can do that for specific pages like with a page of page id 9</p>\n\n<pre><code> //for si...
2016/03/09
[ "https://wordpress.stackexchange.com/questions/220208", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/81042/" ]
I've applied the following code to enable the comment section in the page template. ``` <div class="col-md-12"> <?php while ( have_posts() ) : the_post(); ?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <div class="sec-text wow fadeInUp" data...
I think it *could* be a problem with `get_comments_number` which returns numeric, though theoretically it should test this way too... you could try instead: ``` if ( comments_open() || have_comments() ) : comments_template(); endif; ``` OR ``` if ( comments_open() || (get_comments_number() > 0) ) : comments...
220,214
<p>I'm a newbie for coding, I would like to learn how to add css style conditionally in functions.php My header controlled by <code>.header-outer</code> class. What would it be the best way to add css depending on category? I was able to determine category slug (not standard wordpress category) and wrote some if condit...
[ { "answer_id": 220210, "author": "Chandan Kumar Thakur", "author_id": 88637, "author_profile": "https://wordpress.stackexchange.com/users/88637", "pm_score": 0, "selected": false, "text": "<p>yes you can do that for specific pages like with a page of page id 9</p>\n\n<pre><code> //for si...
2016/03/09
[ "https://wordpress.stackexchange.com/questions/220214", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/32315/" ]
I'm a newbie for coding, I would like to learn how to add css style conditionally in functions.php My header controlled by `.header-outer` class. What would it be the best way to add css depending on category? I was able to determine category slug (not standard wordpress category) and wrote some if conditions. It's wor...
I think it *could* be a problem with `get_comments_number` which returns numeric, though theoretically it should test this way too... you could try instead: ``` if ( comments_open() || have_comments() ) : comments_template(); endif; ``` OR ``` if ( comments_open() || (get_comments_number() > 0) ) : comments...
220,225
<p>I'm using Postman to test my project and the wp-api. More specifically POST requests where a user must be authenticated to do something. Here's what I'm working with to create a user:</p> <pre><code>{{url}}/projectname/wp-json/wp/v2/users/?username=anewname&amp;email=ben@scientifik.com&amp;password=passwordhere </c...
[ { "answer_id": 226822, "author": "MTT", "author_id": 1057, "author_profile": "https://wordpress.stackexchange.com/users/1057", "pm_score": -1, "selected": false, "text": "<p>Postman doesn't need a nonce to create content with v2 beta 12... just use the WP-API Basic Auth plugin. The one h...
2016/03/09
[ "https://wordpress.stackexchange.com/questions/220225", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/18726/" ]
I'm using Postman to test my project and the wp-api. More specifically POST requests where a user must be authenticated to do something. Here's what I'm working with to create a user: ``` {{url}}/projectname/wp-json/wp/v2/users/?username=anewname&email=ben@scientifik.com&password=passwordhere ``` However when testin...
Postman shares cookies with Chrome. If you are logged into your site you may see unexpected results. REF : <https://wordpress.org/support/topic/wp-api-cant-create-a-post/>
220,245
<p>Whats the most simple way to change my wp-menu generated output from <code>&lt;li&gt;&lt;a href=""&gt;nav link&lt;/a&gt;&lt;/li&gt;</code> to <code>&lt;a href=""&gt;&lt;li&gt;&lt;li/&gt;&lt;/a&gt;</code>? Do I create an array in my <code>functions.php</code>?</p> <p>This is what I have in my <code>functions.php</co...
[ { "answer_id": 220253, "author": "Madan Karki", "author_id": 83958, "author_profile": "https://wordpress.stackexchange.com/users/83958", "pm_score": -1, "selected": false, "text": "<p>use <a href=\"https://gist.github.com/toscho/1053467\" rel=\"nofollow\">\"T5_Nav_Menu_Walker_Simple\"</a...
2016/03/10
[ "https://wordpress.stackexchange.com/questions/220245", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60779/" ]
Whats the most simple way to change my wp-menu generated output from `<li><a href="">nav link</a></li>` to `<a href=""><li><li/></a>`? Do I create an array in my `functions.php`? This is what I have in my `functions.php` ``` function register_my_menus() { register_nav_menus( array( 'primary' ...
I don't recommend having anything in-between a ul and li. If you make the anchor tag display:block that fills the list, the whole list tag will be clickable. So dont put any height, width, or padding on the list and manage it all instead with the anchor. ``` a { display: block; width: 100%; } ```
220,270
<p>What I'm trying to do is show the current logged in user's comment at the top of the list in the comments section in Wordpress on any given post. I don't care if it is just duplicated at the top and still shows in the regular order below as well, I just need it to show at the top of the list so the user can find it ...
[ { "answer_id": 220253, "author": "Madan Karki", "author_id": 83958, "author_profile": "https://wordpress.stackexchange.com/users/83958", "pm_score": -1, "selected": false, "text": "<p>use <a href=\"https://gist.github.com/toscho/1053467\" rel=\"nofollow\">\"T5_Nav_Menu_Walker_Simple\"</a...
2016/03/10
[ "https://wordpress.stackexchange.com/questions/220270", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/90312/" ]
What I'm trying to do is show the current logged in user's comment at the top of the list in the comments section in Wordpress on any given post. I don't care if it is just duplicated at the top and still shows in the regular order below as well, I just need it to show at the top of the list so the user can find it eas...
I don't recommend having anything in-between a ul and li. If you make the anchor tag display:block that fills the list, the whole list tag will be clickable. So dont put any height, width, or padding on the list and manage it all instead with the anchor. ``` a { display: block; width: 100%; } ```
220,275
<p>I'm using PHPUnit to Unit Test my WP plugin on top of the WP testing suite. Everything works fine except that when I try to create a table via the setUp method, the table doesn't get created. </p> <p>Here's my code:</p> <pre><code>class Test_Db extends PAO_UnitTestCase { function setUp() { parent::setUp(); ...
[ { "answer_id": 220308, "author": "J.D.", "author_id": 27757, "author_profile": "https://wordpress.stackexchange.com/users/27757", "pm_score": 5, "selected": true, "text": "<p>You've just discovered an important feature of the core test suite: it forces any tables created during the test ...
2016/03/10
[ "https://wordpress.stackexchange.com/questions/220275", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/38261/" ]
I'm using PHPUnit to Unit Test my WP plugin on top of the WP testing suite. Everything works fine except that when I try to create a table via the setUp method, the table doesn't get created. Here's my code: ``` class Test_Db extends PAO_UnitTestCase { function setUp() { parent::setUp(); global $wpdb; ...
You've just discovered an important feature of the core test suite: it forces any tables created during the test to be temporary tables. If you look in the `WP_UnitTestCase::setUp()` method you'll see that [it calls a method called `start_transaction()`](https://core.trac.wordpress.org/browser/trunk/tests/phpunit/incl...
220,278
<p>I am using CMB2 and following code to select date &amp; time:</p> <pre><code>$cmb-&gt;add_field( array( 'name' =&gt; __( 'Test Date/Time Picker Combo (UNIX timestamp)', 'cmb2' ), 'desc' =&gt; __( 'field description (optional)', 'cmb2' ), 'id' =&gt; $prefix . 'datetime_timestamp', '...
[ { "answer_id": 220280, "author": "kraftner", "author_id": 47733, "author_profile": "https://wordpress.stackexchange.com/users/47733", "pm_score": 3, "selected": false, "text": "<p>You're almost there. The number you see is a called <a href=\"https://en.m.wikipedia.org/wiki/Unix_time\" re...
2016/03/10
[ "https://wordpress.stackexchange.com/questions/220278", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/69828/" ]
I am using CMB2 and following code to select date & time: ``` $cmb->add_field( array( 'name' => __( 'Test Date/Time Picker Combo (UNIX timestamp)', 'cmb2' ), 'desc' => __( 'field description (optional)', 'cmb2' ), 'id' => $prefix . 'datetime_timestamp', 'type' => 'text_datetime_timest...
The date/time related field types for CMB2 store all their values as Unix timestamps in the database with the exception of `text_datetime_timestamp_timezone` which stores it's value as a serialized DateTime object. * **text\_date\_timestamp** Date Picker (UNIX timestamp) * **text\_datetime\_timestamp** Text Date/Time ...
220,293
<p>When I call the_content(), I want to show only text and don't want to show images. Notable that, I don't want to remove text style. The text style should be display as well. How can I do this?</p>
[ { "answer_id": 220298, "author": "Kishan Chauhan", "author_id": 63564, "author_profile": "https://wordpress.stackexchange.com/users/63564", "pm_score": 3, "selected": true, "text": "<p>This answer already here <a href=\"https://wordpress.stackexchange.com/questions/162162/how-to-remove-i...
2016/03/10
[ "https://wordpress.stackexchange.com/questions/220293", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/81042/" ]
When I call the\_content(), I want to show only text and don't want to show images. Notable that, I don't want to remove text style. The text style should be display as well. How can I do this?
This answer already here [How to remove images from showing in a post with the\_content()?](https://wordpress.stackexchange.com/questions/162162/how-to-remove-images-from-showing-in-a-post-with-the-content#162165) ``` <?php $content = get_the_content(); $content = preg_replace("/<img[^>]+\>/i", " ", $content); ...
220,326
<p>I'm hoping someone will be able to help me with this issue. I noticed today that when I search certain serch terms in my Wordpress site's search box the link is messed up (shown in the image below outlined by the yellow boxes) and when clicked, the link takes the user to a blank page.</p> <p><a href="https://i.stac...
[ { "answer_id": 220298, "author": "Kishan Chauhan", "author_id": 63564, "author_profile": "https://wordpress.stackexchange.com/users/63564", "pm_score": 3, "selected": true, "text": "<p>This answer already here <a href=\"https://wordpress.stackexchange.com/questions/162162/how-to-remove-i...
2016/03/10
[ "https://wordpress.stackexchange.com/questions/220326", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/90354/" ]
I'm hoping someone will be able to help me with this issue. I noticed today that when I search certain serch terms in my Wordpress site's search box the link is messed up (shown in the image below outlined by the yellow boxes) and when clicked, the link takes the user to a blank page. [![Issue example](https://i.stack...
This answer already here [How to remove images from showing in a post with the\_content()?](https://wordpress.stackexchange.com/questions/162162/how-to-remove-images-from-showing-in-a-post-with-the-content#162165) ``` <?php $content = get_the_content(); $content = preg_replace("/<img[^>]+\>/i", " ", $content); ...
220,330
<p>This is my code. Where I'm wrong? </p> <pre><code>&lt;?php $connection = mysql_connect($DB_HOST, $DB_USER, $DB_PASSWORD); mysql_select_db($DB_NAME); $img = mysql_query("SELECT * FROM wp_bwg_image"); while($res = mysql_fetch_array($img)){ echo $res; } ?&gt; </code></pre> <p>From this t...
[ { "answer_id": 220385, "author": "brianlmerritt", "author_id": 78419, "author_profile": "https://wordpress.stackexchange.com/users/78419", "pm_score": 1, "selected": false, "text": "<p>Use the global $wpdb for example <code>$myrows = $wpdb-&gt;get_results( “insert sql here\");</code></p>...
2016/03/10
[ "https://wordpress.stackexchange.com/questions/220330", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/90333/" ]
This is my code. Where I'm wrong? ``` <?php $connection = mysql_connect($DB_HOST, $DB_USER, $DB_PASSWORD); mysql_select_db($DB_NAME); $img = mysql_query("SELECT * FROM wp_bwg_image"); while($res = mysql_fetch_array($img)){ echo $res; } ?> ``` From this table I want to take any pictures...
Use the global $wpdb for example `$myrows = $wpdb->get_results( “insert sql here");`
220,339
<p>I have a little problem, I created a wordpress theme with documentation created with the site helpscout, to reduce the number of support ticket, I would like to do the same thing EDD: <a href="https://easydigitaldownloads.com/support/" rel="nofollow">https://easydigitaldownloads.com/support/</a>, if you click on "Su...
[ { "answer_id": 220366, "author": "kingkool68", "author_id": 2744, "author_profile": "https://wordpress.stackexchange.com/users/2744", "pm_score": 0, "selected": false, "text": "<p>You're trying to make an AJAX request to another domain which is prohibited by JavaScript for security/priva...
2016/03/10
[ "https://wordpress.stackexchange.com/questions/220339", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/45874/" ]
I have a little problem, I created a wordpress theme with documentation created with the site helpscout, to reduce the number of support ticket, I would like to do the same thing EDD: <https://easydigitaldownloads.com/support/>, if you click on "Submit Support Request", an input appears and if you enter a word, for exa...
I found !!! It had nothing to do with "Access-Control-Allow-Origin" was because of the API key, I entered the username and password from my dashboard help scout, I had to enter the api key for my documentation :) Thanks a lot for your help :)
220,347
<p>I have created a metabox to upload images. Whenever I click on the "Select Image" button the Image Uploader Box successfully pops up but when I select an image and click the "Insert" button the image URL doesn't get inserted in the text field. Please tell me what to do so that whenever I insert an image the image UR...
[ { "answer_id": 220366, "author": "kingkool68", "author_id": 2744, "author_profile": "https://wordpress.stackexchange.com/users/2744", "pm_score": 0, "selected": false, "text": "<p>You're trying to make an AJAX request to another domain which is prohibited by JavaScript for security/priva...
2016/03/10
[ "https://wordpress.stackexchange.com/questions/220347", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/90367/" ]
I have created a metabox to upload images. Whenever I click on the "Select Image" button the Image Uploader Box successfully pops up but when I select an image and click the "Insert" button the image URL doesn't get inserted in the text field. Please tell me what to do so that whenever I insert an image the image URL g...
I found !!! It had nothing to do with "Access-Control-Allow-Origin" was because of the API key, I entered the username and password from my dashboard help scout, I had to enter the api key for my documentation :) Thanks a lot for your help :)
220,349
<p>I have a plugin that is syncing data from a third party service into a custom post type. The idea is that the post type acts as a slave to the third party service, so any changes there overwrite any on the wordpress site. However there will be a few extra custom fields that will be made to add information from the w...
[ { "answer_id": 220371, "author": "majick", "author_id": 76440, "author_profile": "https://wordpress.stackexchange.com/users/76440", "pm_score": 1, "selected": false, "text": "<p>To begin with, adding an <code>_</code> to the start of the custom field key will make it a hidden field not a...
2016/03/10
[ "https://wordpress.stackexchange.com/questions/220349", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/63445/" ]
I have a plugin that is syncing data from a third party service into a custom post type. The idea is that the post type acts as a slave to the third party service, so any changes there overwrite any on the wordpress site. However there will be a few extra custom fields that will be made to add information from the word...
In order to do this I had to hide the fields in the default ACF output. There is no way to do this in the core, underscores can work to disable the output everywhere else but the edit area is an exception. I had used the following code to create a hidden field type, it outputs no input and hides its own label. It is b...
220,376
<p>In the home page, I have a custom loop for displaying different post type content. I have this loop on my index.php</p> <pre><code>$loop = new WP_Query( array( 'post_type' =&gt; array('photo', 'video', 'web'), 'paged' =&gt; get_query_var('paged') ? get_query_var('paged') : 1, 'posts_per_page' =&gt; -1 ...
[ { "answer_id": 220382, "author": "Pieter Goosen", "author_id": 31545, "author_profile": "https://wordpress.stackexchange.com/users/31545", "pm_score": 3, "selected": true, "text": "<p>You are doing it wrong on many levels here:</p>\n\n<ul>\n<li><p>You should not be using a custom query i...
2016/03/11
[ "https://wordpress.stackexchange.com/questions/220376", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/55160/" ]
In the home page, I have a custom loop for displaying different post type content. I have this loop on my index.php ``` $loop = new WP_Query( array( 'post_type' => array('photo', 'video', 'web'), 'paged' => get_query_var('paged') ? get_query_var('paged') : 1, 'posts_per_page' => -1 ) ); ``` Now it dis...
You are doing it wrong on many levels here: * You should not be using a custom query in place of the main query. Rather use `pre_get_posts` to alter the main query accordingly. Go back to the main loop and add the following in your functions file or in a custom plugin ``` add_action( 'pre_get_posts', function ( $q ) ...
220,396
<p>I am using the 'standard' trick for category removal in wordpress. In my permalinks I set the permalinks structure to </p> <pre><code>/%category%/%postname%/ </code></pre> <p>And my category base to </p> <pre><code>. </code></pre> <p>Which worked fine, until the client said he wants parent categories to appear i...
[ { "answer_id": 220790, "author": "CK MacLeod", "author_id": 35923, "author_profile": "https://wordpress.stackexchange.com/users/35923", "pm_score": 2, "selected": false, "text": "<p>The \".\" method was always an unlikely kludge. </p>\n\n<p>The <a href=\"https://wordpress.org/plugins/rem...
2016/03/11
[ "https://wordpress.stackexchange.com/questions/220396", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/58895/" ]
I am using the 'standard' trick for category removal in wordpress. In my permalinks I set the permalinks structure to ``` /%category%/%postname%/ ``` And my category base to ``` . ``` Which worked fine, until the client said he wants parent categories to appear in the header of the article, and the child catego...
The "." method was always an unlikely kludge. The ["Remove Category URL" plug-in](https://wordpress.org/plugins/remove-category-url/) works fine and, in my experience, as advertised. I'm not sure about the basis of the aversion to installing a plug-in for this purpose is, but, if you don't want to do so for some reas...
220,421
<p>I was wondering if it's possible to set up user roles in a way that means that users in certain groups can ONLY edit posts that have a specific taxonomy assigned to them e.g:</p> <pre><code>Properties (Post Type) Taxonomy One Taxonomy Two Taxonomy Three User Roles Group One - Can only edit properti...
[ { "answer_id": 220424, "author": "Jarod Thornton", "author_id": 44017, "author_profile": "https://wordpress.stackexchange.com/users/44017", "pm_score": 0, "selected": false, "text": "<p>I actually dug up that plugin developers blog and this is what he offers as insight.</p>\n\n<blockquot...
2016/03/11
[ "https://wordpress.stackexchange.com/questions/220421", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/78497/" ]
I was wondering if it's possible to set up user roles in a way that means that users in certain groups can ONLY edit posts that have a specific taxonomy assigned to them e.g: ``` Properties (Post Type) Taxonomy One Taxonomy Two Taxonomy Three User Roles Group One - Can only edit properties with 'Taxon...
You might be able to use the filter `user_has_cap` which is used when checking for a particular capability (found in `/wp-includes/class-wp-user.php` in `has_cap`): ``` /** * Dynamically filter a user's capabilities. * * @since 2.0.0 * @since 3.7.0 Added the user object. * * @param ar...
220,435
<p>How can I add the words "Posted on" before the post data in a Twentyfourteen theme's post? The default is only to show the date and clock icon.</p> <p>I'm not sure if this is a basic modification or if it's going to be a fix unique to Twentyfourteen.</p> <p>I found <a href="https://premium.wpmudev.org/blog/remove-...
[ { "answer_id": 220454, "author": "Tom Woodward", "author_id": 82797, "author_profile": "https://wordpress.stackexchange.com/users/82797", "pm_score": 0, "selected": false, "text": "<p>I took a look at the documentation <a href=\"https://codex.wordpress.org/Plugin_API/Filter_Reference/get...
2016/03/11
[ "https://wordpress.stackexchange.com/questions/220435", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/90408/" ]
How can I add the words "Posted on" before the post data in a Twentyfourteen theme's post? The default is only to show the date and clock icon. I'm not sure if this is a basic modification or if it's going to be a fix unique to Twentyfourteen. I found [this web page](https://premium.wpmudev.org/blog/remove-date-from-...
The post date is added by `twentyfourteen_posted_on` as shown in [content.php](https://themes.trac.wordpress.org/browser/twentyfourteen/1.6/content.php#L34). This function is in [/inc/template-tags.php](https://themes.trac.wordpress.org/browser/twentyfourteen/1.6/inc/template-tags.php#L101) and is correctly wrapped in ...
220,471
<p>I'm working on getting the editor to look more like the front end by adding extra CSS to the TinyMCE rich text editor.</p> <p>WordPress adds <code>/wp-includes/js/tinymce/skins/lightgray/content.min.css</code> and <code>/wp-includes/js/tinymce/skins/wordpress/wp-content.css</code> by default.</p> <p>Is there an ea...
[ { "answer_id": 220472, "author": "Tim Malone", "author_id": 46066, "author_profile": "https://wordpress.stackexchange.com/users/46066", "pm_score": 2, "selected": false, "text": "<p>You should be able to remove these by hooking into the <code>mce_css</code> filter in your <code>functions...
2016/03/12
[ "https://wordpress.stackexchange.com/questions/220471", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/41488/" ]
I'm working on getting the editor to look more like the front end by adding extra CSS to the TinyMCE rich text editor. WordPress adds `/wp-includes/js/tinymce/skins/lightgray/content.min.css` and `/wp-includes/js/tinymce/skins/wordpress/wp-content.css` by default. Is there an easy way to remove this?
This is what I arrived at. This will remove just the custom wordpress css `/wp-includes/js/tinymce/skins/wordpress/wp-content.css`. ``` function squarecandy_tinymce_remove_mce_css($stylesheets) { $stylesheets = explode(',',$stylesheets); foreach ($stylesheets as $key => $sheet) { if (preg_match('/wp\-i...
220,473
<p>I need a way to change the themes "Live Preview" url within the Appearance->Themes page? I want the themes thumbnails to link to a demo site showcasing the theme and not open the customizer. I looked into the code some but I am not seeing much for a solution, but was wondering if someone else has a trick for this. T...
[ { "answer_id": 220476, "author": "Tim Malone", "author_id": 46066, "author_profile": "https://wordpress.stackexchange.com/users/46066", "pm_score": 0, "selected": false, "text": "<p>Wordpress seems to call <code>wp_customize_url</code> to get the theme preview URL, and there's not much t...
2016/03/12
[ "https://wordpress.stackexchange.com/questions/220473", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/38434/" ]
I need a way to change the themes "Live Preview" url within the Appearance->Themes page? I want the themes thumbnails to link to a demo site showcasing the theme and not open the customizer. I looked into the code some but I am not seeing much for a solution, but was wondering if someone else has a trick for this. Than...
External *Live Previews* For Themes ----------------------------------- The `Live Preview` buttons, on the `/wp-admin/themes.php` page, are generated from the *tmpl-theme* micro template: ``` <script id="tmpl-wpse" type="text/template"> ...cut... <div class="theme-actions"> <# if ( data.active ...
220,479
<p>Permalinks are (finally) working for individual posts of the custom <code>yoga-event</code> type I've created.</p> <p>And archive works without URL rewriting: </p> <p><code>http://website.localhost/?post_type=yoga-event</code></p> <p>However <code>get_post_type_archive_link( 'yoga-event' )</code> returns false.</...
[ { "answer_id": 220502, "author": "frogg3862", "author_id": 83367, "author_profile": "https://wordpress.stackexchange.com/users/83367", "pm_score": 2, "selected": true, "text": "<p>Can I see your <code>register_post_type</code> line? Those are usually like: <code>register_post_type( 'some...
2016/03/12
[ "https://wordpress.stackexchange.com/questions/220479", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/48604/" ]
Permalinks are (finally) working for individual posts of the custom `yoga-event` type I've created. And archive works without URL rewriting: `http://website.localhost/?post_type=yoga-event` However `get_post_type_archive_link( 'yoga-event' )` returns false. This is the array I'm sending to `register_post_type`: `...
Can I see your `register_post_type` line? Those are usually like: `register_post_type( 'some-post-type', $args );`. In this example, `some-post-type` would be the ID that you use in `get_post_type_archive_link( 'some-post-type' )`, not the rewrite slug `yoga-event`.
220,483
<p>So, I have a few form fields like so:</p> <pre><code>&lt;input name='mainStageSatOrder[theband][theid]' type='hidden' class='band-id' value='' /&gt;"; &lt;input name='mainStageSatOrder[theband][theorder]' type='hidden' class='band-order' value='' /&gt;"; </code></pre> <p>As you can see, these form fields (of which...
[ { "answer_id": 220552, "author": "iantsch", "author_id": 90220, "author_profile": "https://wordpress.stackexchange.com/users/90220", "pm_score": 1, "selected": false, "text": "<p>You got a litte thinking problem with your MD array, it should look like that, otherwise you will overwrite d...
2016/03/12
[ "https://wordpress.stackexchange.com/questions/220483", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/35299/" ]
So, I have a few form fields like so: ``` <input name='mainStageSatOrder[theband][theid]' type='hidden' class='band-id' value='' />"; <input name='mainStageSatOrder[theband][theorder]' type='hidden' class='band-order' value='' />"; ``` As you can see, these form fields (of which there are more, these are just exampl...
First off, there's a problem with your array. Arrays can not have duplicate keys. So, only the first key will be saved. You need to change your form to something like this. ``` <input name='mainStageSatOrder[theband0][theid]' type='hidden' class='band-id' value='' />"; <input name='mainStageSatOrder[theband0][theorde...
220,508
<p>This is My Category List :</p> <p>1- Years 2- Genere</p> <p>And I use This Code For show in posts :</p> <pre><code>&lt;?php the_category(' , ') ?&gt; </code></pre> <p>How Can Hide "Year or Genere" in up code?</p> <p>Please Help Me.i want Show Only One Category.</p>
[ { "answer_id": 220552, "author": "iantsch", "author_id": 90220, "author_profile": "https://wordpress.stackexchange.com/users/90220", "pm_score": 1, "selected": false, "text": "<p>You got a litte thinking problem with your MD array, it should look like that, otherwise you will overwrite d...
2016/03/12
[ "https://wordpress.stackexchange.com/questions/220508", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/90454/" ]
This is My Category List : 1- Years 2- Genere And I use This Code For show in posts : ``` <?php the_category(' , ') ?> ``` How Can Hide "Year or Genere" in up code? Please Help Me.i want Show Only One Category.
First off, there's a problem with your array. Arrays can not have duplicate keys. So, only the first key will be saved. You need to change your form to something like this. ``` <input name='mainStageSatOrder[theband0][theid]' type='hidden' class='band-id' value='' />"; <input name='mainStageSatOrder[theband0][theorde...
220,511
<p>I need to print all terms associated to a custom post type post. In the post template I wrote that code:</p> <pre><code>&lt;?php foreach (get_the_terms(the_ID(), 'taxonomy') as $cat) : ?&gt; &lt;?php echo $cat-&gt;name; ?&gt; &lt;?php endforeach; ?&gt; </code></pre> <p>The loop works correctly, but before the...
[ { "answer_id": 220512, "author": "Sumit", "author_id": 32475, "author_profile": "https://wordpress.stackexchange.com/users/32475", "pm_score": 5, "selected": true, "text": "<p><a href=\"https://codex.wordpress.org/Function_Reference/the_ID\" rel=\"noreferrer\"><code>the_ID()</code></a> p...
2016/03/12
[ "https://wordpress.stackexchange.com/questions/220511", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/90362/" ]
I need to print all terms associated to a custom post type post. In the post template I wrote that code: ``` <?php foreach (get_the_terms(the_ID(), 'taxonomy') as $cat) : ?> <?php echo $cat->name; ?> <?php endforeach; ?> ``` The loop works correctly, but before the list also the id was printed. Like: ``` 37 ta...
[`the_ID()`](https://codex.wordpress.org/Function_Reference/the_ID) print the post ID. You need to use the [`get_the_ID()`](https://developer.wordpress.org/reference/functions/get_the_ID/) which return the post ID. Example: ``` foreach (get_the_terms(get_the_ID(), 'taxonomy') as $cat) { echo $cat->name; } ``` Al...
220,549
<p>I want to add an inline word(s) after comments of post author's name. Suppose, my name is Tiger and i am the post author, so <strong>Post author</strong> will be printed after my name every time when i add a comment on the post.</p> <p><a href="https://i.stack.imgur.com/Ca7iP.png" rel="nofollow noreferrer"><img src...
[ { "answer_id": 220553, "author": "mukto90", "author_id": 57944, "author_profile": "https://wordpress.stackexchange.com/users/57944", "pm_score": 0, "selected": false, "text": "<p>If I'm not getting it wrong, you are going to add some text to commenter's name if he is the post author, rig...
2016/03/13
[ "https://wordpress.stackexchange.com/questions/220549", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/75682/" ]
I want to add an inline word(s) after comments of post author's name. Suppose, my name is Tiger and i am the post author, so **Post author** will be printed after my name every time when i add a comment on the post. [![Like this picture](https://i.stack.imgur.com/Ca7iP.png)](https://i.stack.imgur.com/Ca7iP.png) I don...
Just wanted to mention some alternatives: Alternative #1 -------------- You say you don't want to edit the `comments.php` file in the current theme directory. If we need to change how the `wp_list_comments()` works, we can always modify it through the `wp_list_comments_args` filter. For example to add our own callbac...
220,572
<p>Using WordPress 4.4.2 (latest version as of writing this)</p> <p>I'm trying to use the [video] shortcode to show a video on my site. If I provide a url ending with the <code>filename.mp4</code> it works fine:</p> <p><code>[video src="http://example.com/filename.mp4"]</code></p> <p>but when I add a querystring par...
[ { "answer_id": 220553, "author": "mukto90", "author_id": 57944, "author_profile": "https://wordpress.stackexchange.com/users/57944", "pm_score": 0, "selected": false, "text": "<p>If I'm not getting it wrong, you are going to add some text to commenter's name if he is the post author, rig...
2016/03/13
[ "https://wordpress.stackexchange.com/questions/220572", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/44758/" ]
Using WordPress 4.4.2 (latest version as of writing this) I'm trying to use the [video] shortcode to show a video on my site. If I provide a url ending with the `filename.mp4` it works fine: `[video src="http://example.com/filename.mp4"]` but when I add a querystring parameter to the end of the URL, it refuses to sh...
Just wanted to mention some alternatives: Alternative #1 -------------- You say you don't want to edit the `comments.php` file in the current theme directory. If we need to change how the `wp_list_comments()` works, we can always modify it through the `wp_list_comments_args` filter. For example to add our own callbac...
220,581
<p>I have a main page and beyond that it has children. I successfully rewrite the children like so:</p> <pre><code>add_rewrite_rule('my-url/?([^/]*)', 'index.php?my-var=$matches[1]', 'top'); </code></pre> <p>This works great. But when I try to rewrite the base:</p> <pre><code>add_rewrite_rule('my-url/?', 'index.php?...
[ { "answer_id": 220583, "author": "Milo", "author_id": 4771, "author_profile": "https://wordpress.stackexchange.com/users/4771", "pm_score": 1, "selected": false, "text": "<p>This should work for both, slight adjustments to each regex pattern-</p>\n\n<pre><code>add_rewrite_rule('my-url/([...
2016/03/13
[ "https://wordpress.stackexchange.com/questions/220581", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/85669/" ]
I have a main page and beyond that it has children. I successfully rewrite the children like so: ``` add_rewrite_rule('my-url/?([^/]*)', 'index.php?my-var=$matches[1]', 'top'); ``` This works great. But when I try to rewrite the base: ``` add_rewrite_rule('my-url/?', 'index.php?my-var=main', 'top'); ``` ... it do...
Change your rewrite rules and the order to the following: ``` add_rewrite_rule('my-url/([^/]*)/?$', 'index.php?my-var=$matches[1]', 'top'); add_rewrite_rule('my-url/?$', 'index.php?my-var=main', 'top'); ``` **Why the order?** If the order would be the other way around, the first rule will always apply, so the rulese...
220,587
<p>I am really clueless. I want to do an insertion in my WordPress plugin the problem is it doesn't return any errors nor it insert the stuff!</p> <p>I don't know how to fix this and really need your help. In the following code i used example names, but i used the character <code>-</code> for these in case of that my...
[ { "answer_id": 220615, "author": "Sumit", "author_id": 32475, "author_profile": "https://wordpress.stackexchange.com/users/32475", "pm_score": 0, "selected": false, "text": "<p>Issue exist in the data type format. You've passed <code>array('%s, %s')</code> take a closer look, instead of ...
2016/03/13
[ "https://wordpress.stackexchange.com/questions/220587", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/90515/" ]
I am really clueless. I want to do an insertion in my WordPress plugin the problem is it doesn't return any errors nor it insert the stuff! I don't know how to fix this and really need your help. In the following code i used example names, but i used the character `-` for these in case of that my real table has also n...
Your format is wrong. On your code is should be ``` $insertion = $wpdb->insert($wpdb->prefix . 'table-name-of-plugin', array( 'column-name' => $stringValueForC1, 'second-column-name' => $stringValueForC2 ), array('%s', '%s') ); ``` Notice the change from ``` array('%s, %s') ``` to ``` array('%s', '%s') ```...
220,595
<p>I know that the style.css file needs to be copied to the child theme before being edited for changes. Is that also true for template.php files? If so, do I need to just copy the specific template file only, or should I copy all?</p> <p><strong>UPDATE:</strong></p> <p><em>includes/breadcrumbs.php:</em></p> <pre>...
[ { "answer_id": 220597, "author": "Tom J Nowell", "author_id": 736, "author_profile": "https://wordpress.stackexchange.com/users/736", "pm_score": 2, "selected": false, "text": "<p>You should only copy the files you intend to change, otherwise when the parent theme is updated, it will loa...
2016/03/14
[ "https://wordpress.stackexchange.com/questions/220595", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/89458/" ]
I know that the style.css file needs to be copied to the child theme before being edited for changes. Is that also true for template.php files? If so, do I need to just copy the specific template file only, or should I copy all? **UPDATE:** *includes/breadcrumbs.php:* ``` <?php if ( is_front_page() ) return; if ( c...
Generally, you do not need to copy the complete parent stylesheet to your child theme, you can just copy the particular code in question to your child theme's stylesheet and modify that. As for `functions.php` and any other functions related files, you cannot copy that to your child theme as this will lead to a canno...
220,619
<p>What is the difference between <code>$GLOBALS['wp_the_query']</code> and <code>global $wp_query</code>?</p> <p>Why prefer one over the other?</p>
[ { "answer_id": 220620, "author": "Jebble", "author_id": 81939, "author_profile": "https://wordpress.stackexchange.com/users/81939", "pm_score": 2, "selected": false, "text": "<p>The global keyword imports the variable into the local scope, while $GLOBALS just grants you access to the var...
2016/03/14
[ "https://wordpress.stackexchange.com/questions/220619", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/27196/" ]
What is the difference between `$GLOBALS['wp_the_query']` and `global $wp_query`? Why prefer one over the other?
You have missed one, `$GLOBALS['wp_query']`. For all purposes, `$GLOBALS['wp_query'] === $wp_query`. `$GLOBALS['wp_query']` is however better for readability and should be used instead of `$wp_query`, BUT, that remains personal preference Now, in a perfect world where unicorns rule the world, `$GLOBALS['wp_the_query']...
220,639
<p>When I switched to using a blank theme, the WordPress dashboard disappeared. </p> <p>To re-activate the previous theme I was using (which did have dashboard support), I reset the values of <em>template, stylesheet</em> and <em>current_theme</em> fields in the <em>wp_options</em> table to the previous theme (by man...
[ { "answer_id": 220841, "author": "Monkey Puzzle", "author_id": 48568, "author_profile": "https://wordpress.stackexchange.com/users/48568", "pm_score": 0, "selected": false, "text": "<p>At the server, can you delete (or download and delete) the current non-working theme? The other one (if...
2016/03/14
[ "https://wordpress.stackexchange.com/questions/220639", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/89458/" ]
When I switched to using a blank theme, the WordPress dashboard disappeared. To re-activate the previous theme I was using (which did have dashboard support), I reset the values of *template, stylesheet* and *current\_theme* fields in the *wp\_options* table to the previous theme (by manually entering the theme name)...
In your current theme, you can use switch\_theme('stylesheet') in the index.php of your theme folder.No need to make changes in the database :) ``` <?php switch_theme('twentyfifteen');//Specify the name of stylesheet of intended theme exit; //Rest of the code ?> ``` You can remove the code after use
220,650
<p>I am adding an admin notice via the conventional <code>admin_notice</code> hook in my plugin:</p> <pre><code>function my_admin_notice() { ?&gt; &lt;div class="notice notice-info is-dismissible"&gt; &lt;p&gt;&lt;?php _e( 'some message', 'my-text-domain' ); ?&gt;&lt;/p&gt; &lt;/div&gt; &lt;?php } ...
[ { "answer_id": 220652, "author": "iantsch", "author_id": 90220, "author_profile": "https://wordpress.stackexchange.com/users/90220", "pm_score": 2, "selected": false, "text": "<p>According to the Codex <code>admin_notice</code> does the following:</p>\n\n<blockquote>\n <p>Notices displa...
2016/03/14
[ "https://wordpress.stackexchange.com/questions/220650", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/15010/" ]
I am adding an admin notice via the conventional `admin_notice` hook in my plugin: ``` function my_admin_notice() { ?> <div class="notice notice-info is-dismissible"> <p><?php _e( 'some message', 'my-text-domain' ); ?></p> </div> <?php } if ( my_plugin_show_admin_notice() ) add_action( 'admin_no...
I found out by accident recently that all the notices will be moved to after the first `<h2>` tag on the page inside a `<div class="wrap">`. This gives you some *slight* control in that, for example, on a plugin settings page you can put an empty `<h2></h2>` at the very top if you want to use `<h2>Plugin Title</h2>` wi...
220,661
<p><strong>What I'm trying to do:</strong><br> Make an ajax-powered search button that gets the text from an input and give a list of post id's that match that search.</p> <p>Note: I must probably sound very stupid to 90% of you, but I'm rather new to ajax and wordpress, so if I'm doing it all wrong, it would be great...
[ { "answer_id": 220652, "author": "iantsch", "author_id": 90220, "author_profile": "https://wordpress.stackexchange.com/users/90220", "pm_score": 2, "selected": false, "text": "<p>According to the Codex <code>admin_notice</code> does the following:</p>\n\n<blockquote>\n <p>Notices displa...
2016/03/14
[ "https://wordpress.stackexchange.com/questions/220661", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/87968/" ]
**What I'm trying to do:** Make an ajax-powered search button that gets the text from an input and give a list of post id's that match that search. Note: I must probably sound very stupid to 90% of you, but I'm rather new to ajax and wordpress, so if I'm doing it all wrong, it would be great if someone could point ...
I found out by accident recently that all the notices will be moved to after the first `<h2>` tag on the page inside a `<div class="wrap">`. This gives you some *slight* control in that, for example, on a plugin settings page you can put an empty `<h2></h2>` at the very top if you want to use `<h2>Plugin Title</h2>` wi...
220,680
<p>i had to resize a lot of existing images in my upload folder (around 1k). After reuploading them, Wordpress of course, doesn't recognize the new dimensions. My approach was to just change the size in the _post_meta table. But this looks like this:</p> <pre><code>a:6{s:5:"width";s:3:"330";s:6:"height";s:4:"1067";s:1...
[ { "answer_id": 220684, "author": "Rarst", "author_id": 847, "author_profile": "https://wordpress.stackexchange.com/users/847", "pm_score": 2, "selected": false, "text": "<p>What you are looking at is PHP <a href=\"http://php.net/manual/en/function.serialize.php\" rel=\"nofollow\">seriali...
2016/03/14
[ "https://wordpress.stackexchange.com/questions/220680", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/90571/" ]
i had to resize a lot of existing images in my upload folder (around 1k). After reuploading them, Wordpress of course, doesn't recognize the new dimensions. My approach was to just change the size in the \_post\_meta table. But this looks like this: ``` a:6{s:5:"width";s:3:"330";s:6:"height";s:4:"1067";s:14:"hwstring_...
You could do this via PHP instead of SQL, just get the existing metadata and change what you need to, it will handle the serializing for you: ``` $newwidth = '250'; // or whatever it is $attachments = get_posts(array('post_type'=>'attachment')); foreach ($attachments as $attachment) { $id = $attachment->ID; $m...
220,716
<p>Currently I've tried this process with two browsers: Google Chrome and Mozilla Firefox. Whenever I want to run a JavaScript code on them they show me the raw code instead of executing it. Exactly what I wrote in my Editor will be shown in the browser screen.</p> <p>Hope someone can help.</p> <h2>Edit</h2> <blockq...
[ { "answer_id": 220683, "author": "Howdy_McGee", "author_id": 7355, "author_profile": "https://wordpress.stackexchange.com/users/7355", "pm_score": 4, "selected": false, "text": "<p>The best reason I can find it to separate Logic from Structure or Control from Markup. The handbook on the ...
2016/03/15
[ "https://wordpress.stackexchange.com/questions/220716", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/83327/" ]
Currently I've tried this process with two browsers: Google Chrome and Mozilla Firefox. Whenever I want to run a JavaScript code on them they show me the raw code instead of executing it. Exactly what I wrote in my Editor will be shown in the browser screen. Hope someone can help. Edit ---- > > Hey, am not using wo...
As in many things wordpress, inertia has a lot to do with why things are done in specific way. Early core themes were written using those constructs and later developers copied them because they either did not know better or thought there was some non obvious reason to prefer them. As @Howdy\_McGee said, it is just a ...
220,726
<p>I want to add a support page to my plugin wordpress. My plugin is already developed. Now I want to allow users to contact me for any question. I want the support button to be next to the activate and Update buttons in the plugin add page.</p>
[ { "answer_id": 220728, "author": "denis.stoyanov", "author_id": 76287, "author_profile": "https://wordpress.stackexchange.com/users/76287", "pm_score": 3, "selected": true, "text": "<p>You can use the <a href=\"https://codex.wordpress.org/Plugin_API/Filter_Reference/plugin_action_links_(...
2016/03/15
[ "https://wordpress.stackexchange.com/questions/220726", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/90607/" ]
I want to add a support page to my plugin wordpress. My plugin is already developed. Now I want to allow users to contact me for any question. I want the support button to be next to the activate and Update buttons in the plugin add page.
You can use the [`plugin_action_links_`](https://codex.wordpress.org/Plugin_API/Filter_Reference/plugin_action_links_(plugin_file_name)) filter for that task: ``` add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'add_support_link_wpse_220726' ); function add_support_link_wpse_220726( $links ) { $lin...
220,789
<p>Im experimenting with random theme and "new technology" and Im trying to convert whole front-end to pure JS single page application <em>(no page refreshes - like Facebook, Twitter etc)</em> using <a href="http://wp-api.org/" rel="nofollow">WP REST API</a>, <a href="http://redux.js.org/" rel="nofollow">Redux.js</a> a...
[ { "answer_id": 220792, "author": "Bruno Cantuaria", "author_id": 65717, "author_profile": "https://wordpress.stackexchange.com/users/65717", "pm_score": 0, "selected": false, "text": "<p>You will need to check cookies than (and probably DB) or call a function somehow (maybe ajax or somet...
2016/03/15
[ "https://wordpress.stackexchange.com/questions/220789", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/80903/" ]
Im experimenting with random theme and "new technology" and Im trying to convert whole front-end to pure JS single page application *(no page refreshes - like Facebook, Twitter etc)* using [WP REST API](http://wp-api.org/), [Redux.js](http://redux.js.org/) and [React.js](https://facebook.github.io/react/) and few other...
As you are going to send ajax request from theme (frontend) you need to specify the ajaxurl otherwise it will throw an error "undefined ajaurl" ``` /** * frontend ajax requests. */ wp_enqueue_script( 'frontend-ajax', JS_DIR_URI . 'frontend-ajax.js', array('jquery'), null, true ); wp_localize_script( 'frontend-ajax',...
220,802
<p>I've found several other threads asking this same question, but for some reason I can't seem to make a solution work for me. For clarification, I want to have a custom field that is applied to a post but contains no value so that I can setup a template post (portfolio item in this case) and simply duplicate it aroun...
[ { "answer_id": 220803, "author": "vancoder", "author_id": 26778, "author_profile": "https://wordpress.stackexchange.com/users/26778", "pm_score": 3, "selected": true, "text": "<p>Your third parameter of <code>get_post_meta()</code> is set to <code>false</code>. This means it will return ...
2016/03/15
[ "https://wordpress.stackexchange.com/questions/220802", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/90658/" ]
I've found several other threads asking this same question, but for some reason I can't seem to make a solution work for me. For clarification, I want to have a custom field that is applied to a post but contains no value so that I can setup a template post (portfolio item in this case) and simply duplicate it around b...
Your third parameter of `get_post_meta()` is set to `false`. This means it will return an array. Even though you didn't set a value for this custom field, it will still record an array element in the DB - so `empty()` will return false. Try switching to `true` for your third param. That should return an empty string.
220,822
<p>I am trying to create two additional <strong>add_meta_box</strong> <em>context</em> locations ('after_title' and 'after_editor') within posts.</p> <p>This doesn't appear to do what I think it should. The meta box does appear on the page just within the normal <em>context</em>, not in the new defined <em>context</em...
[ { "answer_id": 220825, "author": "mmm", "author_id": 74311, "author_profile": "https://wordpress.stackexchange.com/users/74311", "pm_score": 0, "selected": false, "text": "<p>these metaboxes appears as <em>normal</em> because <code>add_meta_box()</code> adds them in the loop of the other...
2016/03/16
[ "https://wordpress.stackexchange.com/questions/220822", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/90671/" ]
I am trying to create two additional **add\_meta\_box** *context* locations ('after\_title' and 'after\_editor') within posts. This doesn't appear to do what I think it should. The meta box does appear on the page just within the normal *context*, not in the new defined *context* locations. Does anyone have any insigh...
Here is a fully working dummy plugin to show how to add the new meta box contexts. **STEPS:** 1. Create the plugin structure below and copy the code into *plugin-shell.php*. 2. Leave the style sheets empty. 3. Install and activate the plugin. 4. Navigate to the plugin from the admin menu item 'Plugin Shell | Add New...
220,839
<p>I'd like to create a <em>Multi-Level Associative Object</em> on <code>$.post</code> method using WordPress, in order to make my code cleaner. The problem is, I don't know how to get those values to manipulate on the back-end.</p> <p>This is what I would like to do in <code>my_query.js</code> file, which contains an...
[ { "answer_id": 220846, "author": "Mark Kaplun", "author_id": 23970, "author_profile": "https://wordpress.stackexchange.com/users/23970", "pm_score": 1, "selected": false, "text": "<p>If you want to pass a complex value, your best path is probably to jsonify it. Something like</p>\n\n<pre...
2016/03/16
[ "https://wordpress.stackexchange.com/questions/220839", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/90683/" ]
I'd like to create a *Multi-Level Associative Object* on `$.post` method using WordPress, in order to make my code cleaner. The problem is, I don't know how to get those values to manipulate on the back-end. This is what I would like to do in `my_query.js` file, which contains and handles the **AJAX** request. ``` $....
Actually the solution I've found was very simple and didn't required much. For some reason I wasn't able to retrieve the data inside my **AJAX Function Request** on the Back-end. JavaScript Code --------------- As you can see below I defined the `someValue` property just the way I wanted, very clean and pretty. ``` ...
220,873
<p>I have a custom post type called 'programmes' that details seminar information. Using a form visitors to the site can signup to a specific 'programme', once they have completed the form a new user is created with the following user meta:</p> <ul> <li>programme_id - the post ID of the 'programme' registered on</li> ...
[ { "answer_id": 220874, "author": "Christine Cooper", "author_id": 24875, "author_profile": "https://wordpress.stackexchange.com/users/24875", "pm_score": 0, "selected": false, "text": "<p>I am a bit unsure what your aim is but I can definitely get you on your feet. </p>\n\n<p>So you want...
2016/03/16
[ "https://wordpress.stackexchange.com/questions/220873", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/51458/" ]
I have a custom post type called 'programmes' that details seminar information. Using a form visitors to the site can signup to a specific 'programme', once they have completed the form a new user is created with the following user meta: * programme\_id - the post ID of the 'programme' registered on * programme\_name ...
You could query all the authors and loop through to update their dates. The below query pulls all users who have a `programme_id` of the current `post_id` and allocates an array of their IDs. You can then loop through to update whatever is necessary: ``` /** Save Custom Metaboxes **/ function save_custom_meta_boxes( $...
220,907
<p>Inside functions.php:</p> <pre><code>add_action('init','my_action'); function my_action() { if($dontknow) { $passme = "yes"; } else { $passme = "no"; } } </code></pre> <p>Inside index.php of the current theme:</p> <pre><code>echo $passme; </code></pre> <p>Is there a global to use for...
[ { "answer_id": 220908, "author": "vancoder", "author_id": 26778, "author_profile": "https://wordpress.stackexchange.com/users/26778", "pm_score": 2, "selected": false, "text": "<p>It really depends on the use case. Anything that writes to the DB is probably overkill. Globals are messy. Y...
2016/03/16
[ "https://wordpress.stackexchange.com/questions/220907", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/12035/" ]
Inside functions.php: ``` add_action('init','my_action'); function my_action() { if($dontknow) { $passme = "yes"; } else { $passme = "no"; } } ``` Inside index.php of the current theme: ``` echo $passme; ``` Is there a global to use for this purpose? Shall I use add\_option (this is n...
Use an object to keep the value of the variable and a custom action to print it out. In your theme’s `functions.php`, create a class, or better: move the class to a separate file. ``` class PassCheck { private $passed = 'no'; public function check() { if ( is_user_logged_in() ) $this-...
220,911
<p>Came across this function to check if a page exists by its slug and it works great</p> <pre><code>function the_slug_exists($post_name) { global $wpdb; if($wpdb-&gt;get_row("SELECT post_name FROM wp_posts WHERE post_name = '" . $post_name . "'", 'ARRAY_A')) { return true; } else { return false; } </code></pr...
[ { "answer_id": 220913, "author": "Motaz M. El Shazly", "author_id": 90216, "author_profile": "https://wordpress.stackexchange.com/users/90216", "pm_score": 0, "selected": false, "text": "<p>Here is an update to the same code for you</p>\n\n<pre><code>function the_slug_exists($post_name) ...
2016/03/17
[ "https://wordpress.stackexchange.com/questions/220911", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/90734/" ]
Came across this function to check if a page exists by its slug and it works great ``` function the_slug_exists($post_name) { global $wpdb; if($wpdb->get_row("SELECT post_name FROM wp_posts WHERE post_name = '" . $post_name . "'", 'ARRAY_A')) { return true; } else { return false; } ``` } but what i'm needin...
looking at MySQL query in the function it becomes clear that though it matches the post\_name and returns true or false. What you want to find is, if a page exists by its slug. So, in that case, the function you have chosen is wrong. To get the page by title you can simply use: ``` $page = get_page_by_title( 'Sample ...
220,930
<p>I'm using V2.0 and trying to create a post using the /posts endpoint.</p> <p>Here's the payload being sent with my request:</p> <pre><code>var payload = { title : "some title", format : "link", tags: ["tag1", "tag2"], categories: ["newsletter"], content: "http://someurl.com", statu...
[ { "answer_id": 221047, "author": "Jevuska", "author_id": 18731, "author_profile": "https://wordpress.stackexchange.com/users/18731", "pm_score": 2, "selected": false, "text": "<p>You are using name in your terms. In default, try to use the existing term id ( in your case, cat ID and tag ...
2016/03/17
[ "https://wordpress.stackexchange.com/questions/220930", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/37198/" ]
I'm using V2.0 and trying to create a post using the /posts endpoint. Here's the payload being sent with my request: ``` var payload = { title : "some title", format : "link", tags: ["tag1", "tag2"], categories: ["newsletter"], content: "http://someurl.com", status: "publish" }; `...
You are using name in your terms. In default, try to use the existing term id ( in your case, cat ID and tag ID ). If you see <https://plugins.trac.wordpress.org/browser/rest-api/trunk/lib/endpoints/class-wp-rest-posts-controller.php#L918> they will handle your term with sanitize them into non-negative integer using `...
220,935
<p>I'm trying to create a custom plugin where I want create a table when the plugin gets activated. I have tried the following code but it is not creating the table in the database </p> <pre><code>function create_plugin_database_table() { global $wpdb; $table_name = $wpdb-&gt;prefix . 'sandbox'; $sql = "CREATE TABL...
[ { "answer_id": 220939, "author": "dipika", "author_id": 90752, "author_profile": "https://wordpress.stackexchange.com/users/90752", "pm_score": 5, "selected": true, "text": "<p>You have to include wpadmin/upgrade-functions.php file to create a table \nexample </p>\n\n<pre><code>function ...
2016/03/17
[ "https://wordpress.stackexchange.com/questions/220935", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/90556/" ]
I'm trying to create a custom plugin where I want create a table when the plugin gets activated. I have tried the following code but it is not creating the table in the database ``` function create_plugin_database_table() { global $wpdb; $table_name = $wpdb->prefix . 'sandbox'; $sql = "CREATE TABLE $table_name ( ...
You have to include wpadmin/upgrade-functions.php file to create a table example ``` function create_plugin_database_table() { global $table_prefix, $wpdb; $tblname = 'pin'; $wp_track_table = $table_prefix . "$tblname "; #Check to see if the table exists already, if not, then create it if($wpd...
220,942
<p>I'm able to get certain info about the active theme using <code>wp_get_theme()</code>. For example:</p> <pre><code>$theme = wp_get_theme(); echo $theme-&gt;get( 'TextDomain' ); // twentyfifteen echo $theme-&gt;get( 'ThemeURI' ); // https://wordpress.org/themes/twentyfifteen/ </code></pre> <p>Is there a way to get ...
[ { "answer_id": 220953, "author": "Bhavesh Nariya", "author_id": 90760, "author_profile": "https://wordpress.stackexchange.com/users/90760", "pm_score": -1, "selected": false, "text": "<p>Yo can get it by <code>get_template_directory_uri()</code></p>\n" }, { "answer_id": 220954, ...
2016/03/17
[ "https://wordpress.stackexchange.com/questions/220942", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/22599/" ]
I'm able to get certain info about the active theme using `wp_get_theme()`. For example: ``` $theme = wp_get_theme(); echo $theme->get( 'TextDomain' ); // twentyfifteen echo $theme->get( 'ThemeURI' ); // https://wordpress.org/themes/twentyfifteen/ ``` Is there a way to get the theme's slug? In this case it'd be *twe...
I found the closest thing to the theme's slug is the theme's directory name. This can be found using `get_template()`: ``` echo get_template(); // twentyfifteen ``` Ref: <https://codex.wordpress.org/Function_Reference/get_template>
220,944
<p>Is it possible to use 2 shortcodes with the same function and change only the post type in the function depending on what shortcode it is?</p> <p>For instance, when I use <code>all_faq</code> shortcode the post type should be Faq. When I use <code>wordpress_faq</code> then the post type should be <code>wp-Faq</code...
[ { "answer_id": 220945, "author": "mmm", "author_id": 74311, "author_profile": "https://wordpress.stackexchange.com/users/74311", "pm_score": 1, "selected": false, "text": "<p>the callback function has 3 parameters and the 3rd is the tag name : </p>\n\n<pre><code>add_shortcode( 'all_faq',...
2016/03/17
[ "https://wordpress.stackexchange.com/questions/220944", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/90756/" ]
Is it possible to use 2 shortcodes with the same function and change only the post type in the function depending on what shortcode it is? For instance, when I use `all_faq` shortcode the post type should be Faq. When I use `wordpress_faq` then the post type should be `wp-Faq`. It works now but is it possible to make ...
the callback function has 3 parameters and the 3rd is the tag name : ``` add_shortcode( 'all_faq', 'commonFunction' ); add_shortcode( 'wordpress_faq', 'commonFunction' ); function commonFunction($attr, $content, $tag) { $cores = [ "all_faq" => "Faq", "wordpress_faq" => "wp-Faq", ]; $arg...
220,946
<p>I am creating a WordPress plugin to help people protect their content from being copied. There are many plugins to protect content from being copied when JavaScript is on, but no plugins which protect content even when JS is off.</p> <p>How can I add the following custom CSS code in a PHP file, to protect content c...
[ { "answer_id": 220948, "author": "RiaanP", "author_id": 66345, "author_profile": "https://wordpress.stackexchange.com/users/66345", "pm_score": 2, "selected": true, "text": "<p>I know this sounds like it's a good idea, but anyone can simply just view the source of the page and take whate...
2016/03/17
[ "https://wordpress.stackexchange.com/questions/220946", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/90758/" ]
I am creating a WordPress plugin to help people protect their content from being copied. There are many plugins to protect content from being copied when JavaScript is on, but no plugins which protect content even when JS is off. How can I add the following custom CSS code in a PHP file, to protect content copy via CS...
I know this sounds like it's a good idea, but anyone can simply just view the source of the page and take whatever they want from there. They can also simply just hit Ctrl+S on their keyboard and save that entire page to their hard drive. They could even screenshot the page and use OCR technology to simply pull the tex...
220,979
<p>I'd like to include in my website a feature for users to only see posts from a certain author and a certain category. I'm able to do it separately but I can't seem to understand how to do it simultaneously.</p>
[ { "answer_id": 220980, "author": "Aamer Shahzad", "author_id": 42772, "author_profile": "https://wordpress.stackexchange.com/users/42772", "pm_score": -1, "selected": false, "text": "<p>use WP_Query() author parameters &amp; category parameters</p>\n\n<p><a href=\"https://codex.wordpress...
2016/03/17
[ "https://wordpress.stackexchange.com/questions/220979", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/90779/" ]
I'd like to include in my website a feature for users to only see posts from a certain author and a certain category. I'm able to do it separately but I can't seem to understand how to do it simultaneously.
If you want your visitors to choose the category and author you can use the code below. If your loop in the template hasn't been changed you should get away with adding a query to the URL like so: `http://website.com/post-title/?author=1&cat=1` If you have a custom query you could do the following: ``` $author = $_...
221,019
<p>this is my source</p> <pre><code> global $page; $page_exists = $page-&gt;post_title; $another_db_user = 'user'; $another_db_pass = 'pass'; $another_db_name = 'name'; $another_db_host = 'localhost'; $another_tb_prefix = 'wp_'; $mydb = new wpdb($another_db_user,$another_db_pass,$anoth...
[ { "answer_id": 220980, "author": "Aamer Shahzad", "author_id": 42772, "author_profile": "https://wordpress.stackexchange.com/users/42772", "pm_score": -1, "selected": false, "text": "<p>use WP_Query() author parameters &amp; category parameters</p>\n\n<p><a href=\"https://codex.wordpress...
2016/03/18
[ "https://wordpress.stackexchange.com/questions/221019", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/86437/" ]
this is my source ``` global $page; $page_exists = $page->post_title; $another_db_user = 'user'; $another_db_pass = 'pass'; $another_db_name = 'name'; $another_db_host = 'localhost'; $another_tb_prefix = 'wp_'; $mydb = new wpdb($another_db_user,$another_db_pass,$another_db_name,$anoth...
If you want your visitors to choose the category and author you can use the code below. If your loop in the template hasn't been changed you should get away with adding a query to the URL like so: `http://website.com/post-title/?author=1&cat=1` If you have a custom query you could do the following: ``` $author = $_...
221,092
<p>I use Bootstrap Modals plugin. I have put the following code for modal in my page-contact.php.</p> <pre><code>&lt;h2&gt;Small Modal&lt;/h2&gt; &lt;button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal"&gt;Open Small Modal&lt;/button&gt; &lt;div class="modal fade" id="myModal" r...
[ { "answer_id": 220980, "author": "Aamer Shahzad", "author_id": 42772, "author_profile": "https://wordpress.stackexchange.com/users/42772", "pm_score": -1, "selected": false, "text": "<p>use WP_Query() author parameters &amp; category parameters</p>\n\n<p><a href=\"https://codex.wordpress...
2016/03/18
[ "https://wordpress.stackexchange.com/questions/221092", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/90864/" ]
I use Bootstrap Modals plugin. I have put the following code for modal in my page-contact.php. ``` <h2>Small Modal</h2> <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Small Modal</button> <div class="modal fade" id="myModal" role="dialog"> <div class="modal-dialog mo...
If you want your visitors to choose the category and author you can use the code below. If your loop in the template hasn't been changed you should get away with adding a query to the URL like so: `http://website.com/post-title/?author=1&cat=1` If you have a custom query you could do the following: ``` $author = $_...
221,108
<p>Just finished moving my local Wordpress install to a live server. Imported my DB, and uploaded my core files to the new server. I also changed the siteurl and home fields in the wp_options table and added the new credentials to the new wp_config file.</p> <p>Basically followed all the directions <a href="http://...
[ { "answer_id": 221111, "author": "nicogaldo", "author_id": 87880, "author_profile": "https://wordpress.stackexchange.com/users/87880", "pm_score": 4, "selected": true, "text": "<p>Go to settings » permalinks and save changes again.</p>\n" }, { "answer_id": 399291, "author": "...
2016/03/18
[ "https://wordpress.stackexchange.com/questions/221108", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/87989/" ]
Just finished moving my local Wordpress install to a live server. Imported my DB, and uploaded my core files to the new server. I also changed the siteurl and home fields in the wp\_options table and added the new credentials to the new wp\_config file. Basically followed all the directions [here](http://www.wpbeginne...
Go to settings » permalinks and save changes again.
221,201
<p>I would like to style two MediaElement players on the same page differently, and figured out the easier way to do this (compared to adding a completely new shortcode and enqueueing a new stylesheet, <a href="https://stackoverflow.com/questions/36111811/wordpress-4-4-media-player-different-css-stylesheet-depending-on...
[ { "answer_id": 221203, "author": "Jevuska", "author_id": 18731, "author_profile": "https://wordpress.stackexchange.com/users/18731", "pm_score": 2, "selected": false, "text": "<p>There are no options to add <code>class</code> as parameter in shortcode <a href=\"https://codex.wordpress.or...
2016/03/20
[ "https://wordpress.stackexchange.com/questions/221201", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/90910/" ]
I would like to style two MediaElement players on the same page differently, and figured out the easier way to do this (compared to adding a completely new shortcode and enqueueing a new stylesheet, [which I couldn't get working either](https://stackoverflow.com/questions/36111811/wordpress-4-4-media-player-different-c...
WordPress allows least three options to manipulate the code to your needs. 1. Use a global variable that you increment with @Jevuska 's answer. ``` global $my_audio_player_count; $my_audio_player_count = 0; add_filter( 'wp_audio_shortcode_class', 'wpse221201_audio_shortcode_class', 1, 1 ); function wpse221201_audio_...
221,202
<p>I am starting a bit with the REST API. If I am not completly mislead, the <code>init</code> action hook is also executed when its a REST API request. Now, I want to execute some code only, when it is not a REST API request.</p> <p>So I was looking for a command like <code>is_rest()</code> in order to do something l...
[ { "answer_id": 221289, "author": "birgire", "author_id": 26350, "author_profile": "https://wordpress.stackexchange.com/users/26350", "pm_score": 5, "selected": true, "text": "<p>It's a good point by @Milo, the <code>REST_REQUEST</code> constant is <a href=\"https://github.com/WordPress/W...
2016/03/20
[ "https://wordpress.stackexchange.com/questions/221202", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/48693/" ]
I am starting a bit with the REST API. If I am not completly mislead, the `init` action hook is also executed when its a REST API request. Now, I want to execute some code only, when it is not a REST API request. So I was looking for a command like `is_rest()` in order to do something like ``` <?php if( ! is_rest() )...
It's a good point by @Milo, the `REST_REQUEST` constant is [defined](https://github.com/WordPress/WordPress/blob/8e41746cb11271d063608a63e3f6091a8685e677/wp-includes/rest-api.php#L135-L141) as `true`, within `rest_api_loaded()` if `$GLOBALS['wp']->query_vars['rest_route']` is non-empty. It's [hooked](https://github.co...
221,240
<p>I am developing a site that has an SSL certificate. I've activated wp-admin being conducted over https (using <code>define('FORCE_SSL_ADMIN', true);</code> in wp-config.php).</p> <p>It's created a lot of issues using wp-admin.</p> <p>1) Whilst doing things in wp-admin I'll regularly get a message saying the sessio...
[ { "answer_id": 221289, "author": "birgire", "author_id": 26350, "author_profile": "https://wordpress.stackexchange.com/users/26350", "pm_score": 5, "selected": true, "text": "<p>It's a good point by @Milo, the <code>REST_REQUEST</code> constant is <a href=\"https://github.com/WordPress/W...
2016/03/21
[ "https://wordpress.stackexchange.com/questions/221240", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/11064/" ]
I am developing a site that has an SSL certificate. I've activated wp-admin being conducted over https (using `define('FORCE_SSL_ADMIN', true);` in wp-config.php). It's created a lot of issues using wp-admin. 1) Whilst doing things in wp-admin I'll regularly get a message saying the session has expired. As far as I c...
It's a good point by @Milo, the `REST_REQUEST` constant is [defined](https://github.com/WordPress/WordPress/blob/8e41746cb11271d063608a63e3f6091a8685e677/wp-includes/rest-api.php#L135-L141) as `true`, within `rest_api_loaded()` if `$GLOBALS['wp']->query_vars['rest_route']` is non-empty. It's [hooked](https://github.co...
221,250
<p>I want to get category id by name so I am using <a href="https://codex.wordpress.org/Function_Reference/get_term_by" rel="nofollow">get_term_by</a></p> <p>This is working fine when name is simple but when '&amp;' is coming in term name it is not fetching category id.</p> <p>e.g I have a term named "Website Develop...
[ { "answer_id": 221289, "author": "birgire", "author_id": 26350, "author_profile": "https://wordpress.stackexchange.com/users/26350", "pm_score": 5, "selected": true, "text": "<p>It's a good point by @Milo, the <code>REST_REQUEST</code> constant is <a href=\"https://github.com/WordPress/W...
2016/03/21
[ "https://wordpress.stackexchange.com/questions/221250", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/89273/" ]
I want to get category id by name so I am using [get\_term\_by](https://codex.wordpress.org/Function_Reference/get_term_by) This is working fine when name is simple but when '&' is coming in term name it is not fetching category id. e.g I have a term named "Website Development & Designing" under **skills** taxonomy a...
It's a good point by @Milo, the `REST_REQUEST` constant is [defined](https://github.com/WordPress/WordPress/blob/8e41746cb11271d063608a63e3f6091a8685e677/wp-includes/rest-api.php#L135-L141) as `true`, within `rest_api_loaded()` if `$GLOBALS['wp']->query_vars['rest_route']` is non-empty. It's [hooked](https://github.co...