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 |
|---|---|---|---|---|---|---|
231,114 | <p>I have a loop that pulls in all sites in my multisite site network and loops through them to get variables located in their ACF options. Here is an excerpt from the code I am using:</p>
<pre><code> $stageurl = array();
$args = array(
'public' => true,
'limit' => 500
);
... | [
{
"answer_id": 231121,
"author": "birgire",
"author_id": 26350,
"author_profile": "https://wordpress.stackexchange.com/users/26350",
"pm_score": 3,
"selected": true,
"text": "<h2>Using <code>get_sites()</code> in WP 4.6+</h2>\n\n<p>It looks like <code>wp_get_sites()</code> will be <a hre... | 2016/06/30 | [
"https://wordpress.stackexchange.com/questions/231114",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/88515/"
] | I have a loop that pulls in all sites in my multisite site network and loops through them to get variables located in their ACF options. Here is an excerpt from the code I am using:
```
$stageurl = array();
$args = array(
'public' => true,
'limit' => 500
);
$sites = wp_get_sit... | Using `get_sites()` in WP 4.6+
------------------------------
It looks like `wp_get_sites()` will be [deprecated](https://github.com/WordPress/WordPress/blob/858fb83f57a2aa916f29bdb04f2d5335c78d5903/wp-includes/ms-deprecated.php#L442) in WP 4.6.
The [new replacement](https://github.com/WordPress/WordPress/blob/858fb8... |
231,118 | <p>I hope this is not too specific to WooCommerce.</p>
<p>I have a nifty shortcode that displays a list of all my products with SKUs. However, it also includes products that I have published but have set the catalog visibility to "hidden." </p>
<p>I can't find an argument / parameter to exclude hidden products (or on... | [
{
"answer_id": 231120,
"author": "Howdy_McGee",
"author_id": 7355,
"author_profile": "https://wordpress.stackexchange.com/users/7355",
"pm_score": 3,
"selected": true,
"text": "<p><strong>Important:</strong> The following only works for WooCommerce versions less than 3.0. For a more up-t... | 2016/06/30 | [
"https://wordpress.stackexchange.com/questions/231118",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/97616/"
] | I hope this is not too specific to WooCommerce.
I have a nifty shortcode that displays a list of all my products with SKUs. However, it also includes products that I have published but have set the catalog visibility to "hidden."
I can't find an argument / parameter to exclude hidden products (or only include those ... | **Important:** The following only works for WooCommerce versions less than 3.0. For a more up-to-date answer please see the other [answer by kalle](https://wordpress.stackexchange.com/a/262628/7355).
WooCommerce save this data as `metadata` so you'll need to run a [Meta Query](https://codex.wordpress.org/Class_Referen... |
231,123 | <p>I have used <code>WP-Mail-SMTP</code> to setup the mailer on my WordPress installation.
I have tested it by sending email to my private mail.</p>
<p>I am now trying to send the form data using wp_mail() function[WP]. </p>
<p>Below is the code.</p>
<pre><code><?php
if(isset($_POST["button_pressed"])){
// Checki... | [
{
"answer_id": 231129,
"author": "Syed Fakhar Abbas",
"author_id": 90591,
"author_profile": "https://wordpress.stackexchange.com/users/90591",
"pm_score": 0,
"selected": false,
"text": "<p>I have checked your code. I think header not defined properly.Please check the code below:</p>\n\n<... | 2016/06/30 | [
"https://wordpress.stackexchange.com/questions/231123",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/97618/"
] | I have used `WP-Mail-SMTP` to setup the mailer on my WordPress installation.
I have tested it by sending email to my private mail.
I am now trying to send the form data using wp\_mail() function[WP].
Below is the code.
```
<?php
if(isset($_POST["button_pressed"])){
// Checking For Blank Fields..
if($_POST["dname"]=... | After fiddling around for hours, I found the problem.
It was the form not the PHP.
```
<div class="col-sm-6">
<input class="form-control" type="text" placeholder="ENTER DOG'S NAME" id="dname" /></div>
<div class="col-sm-6">
<input class="form-control" type="text" placeholder="ENTER OWNER'S NAME" id="name" /></div>
`... |
231,125 | <p>If set <code>show_ui</code> <code>false</code>, this hide the taxonomy meta box and admin menu link both, how to hide only meta box?</p>
<pre><code>$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => false,
'show_admin_column' => false,
... | [
{
"answer_id": 231174,
"author": "NateWr",
"author_id": 39309,
"author_profile": "https://wordpress.stackexchange.com/users/39309",
"pm_score": 4,
"selected": true,
"text": "<p>You're looking for the <code>meta_box_cb</code> argument.</p>\n\n<pre><code>$args = array(\n 'hierarchical' ... | 2016/06/30 | [
"https://wordpress.stackexchange.com/questions/231125",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/97619/"
] | If set `show_ui` `false`, this hide the taxonomy meta box and admin menu link both, how to hide only meta box?
```
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => false,
'show_admin_column' => false,
'show_in_menu' => true,
'show_in_nav_me... | You're looking for the `meta_box_cb` argument.
```
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => false,
'show_admin_column' => false,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'query_var' => true,
'rewrite' ... |
231,130 | <p>Looking at <a href="https://codex.wordpress.org/Function_Reference/human_time_diff" rel="nofollow">https://codex.wordpress.org/Function_Reference/human_time_diff</a></p>
<p>I'm using an English version of Wordpress.</p>
<p>In my theme template, I would like to define custom text of min, hour, day, week, month, yea... | [
{
"answer_id": 231176,
"author": "TheDeadMedic",
"author_id": 1685,
"author_profile": "https://wordpress.stackexchange.com/users/1685",
"pm_score": 2,
"selected": false,
"text": "<p>If you check out the source of <code>human_time_diff</code>:</p>\n\n<pre><code>if ( $diff < HOUR_IN_SEC... | 2016/06/30 | [
"https://wordpress.stackexchange.com/questions/231130",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/92505/"
] | Looking at <https://codex.wordpress.org/Function_Reference/human_time_diff>
I'm using an English version of Wordpress.
In my theme template, I would like to define custom text of min, hour, day, week, month, year in Chinese using `human_time_diff()` when looping through posts.
According to the instruction in the Cod... | The full solution that works for me without modifying the Wordpress core is to clone the `human_time_diff()` function and place it inside `functions.php` as a renamed `human_time_diff_chinese()`, then swap all occurrence of `human_time_diff()` function with this new `human_time_diff_chinese()` function.
```
function h... |
231,137 | <p>I'm very new to this API, in fact I've only spent couple hours on it so far. I've done my research but cannot find anything about it...</p>
<p>The issue is, I can't seem to get the featured image of a post. The JSON returns <code>"featured_media: 0"</code>.</p>
<pre><code>getPosts: function() {
var burl = "http:... | [
{
"answer_id": 231138,
"author": "Michael Cropper",
"author_id": 91911,
"author_profile": "https://wordpress.stackexchange.com/users/91911",
"pm_score": 3,
"selected": false,
"text": "<p>Take a look at a plugin called <a href=\"https://wordpress.org/plugins/better-rest-api-featured-image... | 2016/06/30 | [
"https://wordpress.stackexchange.com/questions/231137",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/97623/"
] | I'm very new to this API, in fact I've only spent couple hours on it so far. I've done my research but cannot find anything about it...
The issue is, I can't seem to get the featured image of a post. The JSON returns `"featured_media: 0"`.
```
getPosts: function() {
var burl = "http://www.example.com/wp-json/wp/v2/... | You can get it without plugins by adding `_embed`as param to your query
```
/?rest_route=/wp/v2/posts&_embed
/wp-json/wp/v2/posts?_embed
``` |
231,144 | <p>Basically a post is an event therefor will be displayed once or twice, depending on meta key.
Every post has at least two meta keys <code>$start_time_1</code> and <code>$end_time_1</code>. Let's say i have two posts, title: "Radio Show" and "TV Show". </p>
<pre><code>Radio Show - start @ 2016-07-01 12:00
TV Show - ... | [
{
"answer_id": 231153,
"author": "Samuel E. Cerezo",
"author_id": 97635,
"author_profile": "https://wordpress.stackexchange.com/users/97635",
"pm_score": 0,
"selected": false,
"text": "<p>What about using this?</p>\n\n<pre>\n$args = array(\n 'post_type' => 'post',\n 'posts_per_page... | 2016/07/01 | [
"https://wordpress.stackexchange.com/questions/231144",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/97628/"
] | Basically a post is an event therefor will be displayed once or twice, depending on meta key.
Every post has at least two meta keys `$start_time_1` and `$end_time_1`. Let's say i have two posts, title: "Radio Show" and "TV Show".
```
Radio Show - start @ 2016-07-01 12:00
TV Show - start @ 2016-07-01 15:00
```
My co... | As Tim Malone said, WP\_Query isn't going to return multiple copies of the same post in its result set. I think you have a design problem and I would suggest you use parent/child posts rather than post meta to accomplish what you want.
The following is one approach to doing this. First, register both post types:
```
... |
231,152 | <p>I am very well aware of <code>how to make multiple sidebars</code>. But I believe my way is not proper way of adding multiple sidebars.</p>
<p><strong>This is how I add multiple sidebars</strong></p>
<p>If I simply wants to create a sidebar then I use sidebar.php file. BUT if I want to use another sidebar then I h... | [
{
"answer_id": 231160,
"author": "cjbj",
"author_id": 75495,
"author_profile": "https://wordpress.stackexchange.com/users/75495",
"pm_score": 2,
"selected": false,
"text": "<p>You can differentiate between sidebars <strong>inside</strong> <code>sidebar.php</code>. I don't know what your ... | 2016/07/01 | [
"https://wordpress.stackexchange.com/questions/231152",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/81621/"
] | I am very well aware of `how to make multiple sidebars`. But I believe my way is not proper way of adding multiple sidebars.
**This is how I add multiple sidebars**
If I simply wants to create a sidebar then I use sidebar.php file. BUT if I want to use another sidebar then I have to create another php file
like `side... | Defining new sidebar with in your functions.php
```
<?php
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>'
));
}?>
```
On... |
231,154 | <p>I am new with word press and I want to show the post of a specific category on my page. The name of the category which i want to show is <code>home slider</code>. Below is the code which I have used to display all the posts <code>title</code>, <code>image</code> and <code>content</code>.</p>
<pre><code><div clas... | [
{
"answer_id": 231160,
"author": "cjbj",
"author_id": 75495,
"author_profile": "https://wordpress.stackexchange.com/users/75495",
"pm_score": 2,
"selected": false,
"text": "<p>You can differentiate between sidebars <strong>inside</strong> <code>sidebar.php</code>. I don't know what your ... | 2016/07/01 | [
"https://wordpress.stackexchange.com/questions/231154",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/97583/"
] | I am new with word press and I want to show the post of a specific category on my page. The name of the category which i want to show is `home slider`. Below is the code which I have used to display all the posts `title`, `image` and `content`.
```
<div class="row">
<?php $myposts = get_posts( 'numberp... | Defining new sidebar with in your functions.php
```
<?php
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>'
));
}?>
```
On... |
231,165 | <p>We have created a CPT which allows our customer to upload files from the admin page to a folder outside of the wp-content/uploads folder. Files are uploaded and manipulated using wp_handle_upload and wp_insert_attachment.</p>
<p>How do we prevent these files from showing in the media library? Can we filter by post ... | [
{
"answer_id": 231201,
"author": "bravokeyl",
"author_id": 43098,
"author_profile": "https://wordpress.stackexchange.com/users/43098",
"pm_score": 4,
"selected": true,
"text": "<p>Media items are just like posts with <strong><code>post_type = attachment</code></strong> and <strong><code>... | 2016/07/01 | [
"https://wordpress.stackexchange.com/questions/231165",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/84924/"
] | We have created a CPT which allows our customer to upload files from the admin page to a folder outside of the wp-content/uploads folder. Files are uploaded and manipulated using wp\_handle\_upload and wp\_insert\_attachment.
How do we prevent these files from showing in the media library? Can we filter by post type?
... | Media items are just like posts with **`post_type = attachment`** and **`post_status = inherit`**.
when we are on `upload.php` page, we have two views:
* List View
* Grid View
Grid view is populated via JavaScript and list view is extending normal **`WP_List_Table`**.
Since it (List view) is using normal post query... |
231,185 | <p>I installed WordPress in my root directory <code>http://coinauctionshelp.com</code>. I want to redirect pages in the root to the new wordpress pages using an .htaccess file like this </p>
<p>301 redirect </p>
<pre><code>http://coinauctionshelp.com/United_States_Coin_Mintages_Price_Guides.html
http://coinauctionshe... | [
{
"answer_id": 231201,
"author": "bravokeyl",
"author_id": 43098,
"author_profile": "https://wordpress.stackexchange.com/users/43098",
"pm_score": 4,
"selected": true,
"text": "<p>Media items are just like posts with <strong><code>post_type = attachment</code></strong> and <strong><code>... | 2016/07/01 | [
"https://wordpress.stackexchange.com/questions/231185",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/-1/"
] | I installed WordPress in my root directory `http://coinauctionshelp.com`. I want to redirect pages in the root to the new wordpress pages using an .htaccess file like this
301 redirect
```
http://coinauctionshelp.com/United_States_Coin_Mintages_Price_Guides.html
http://coinauctionshelp.com/us-coin-values/
```
Wh... | Media items are just like posts with **`post_type = attachment`** and **`post_status = inherit`**.
when we are on `upload.php` page, we have two views:
* List View
* Grid View
Grid view is populated via JavaScript and list view is extending normal **`WP_List_Table`**.
Since it (List view) is using normal post query... |
231,212 | <p>How to get term by custom term meta and taxonomy or how to filter <code>tax_query</code> by term meta instead <code>slug</code>/<code>id</code>?</p>
<pre><code>function custom_pre_get_posts($query)
{
global $wp_query;
if ( !is_admin() && is_shop() && $query->is_main_query() && i... | [
{
"answer_id": 231242,
"author": "edwardr",
"author_id": 25724,
"author_profile": "https://wordpress.stackexchange.com/users/25724",
"pm_score": 2,
"selected": false,
"text": "<p>You'll need to loop through each of the terms in your main query conditional. Assuming there will likely be m... | 2016/07/01 | [
"https://wordpress.stackexchange.com/questions/231212",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/97619/"
] | How to get term by custom term meta and taxonomy or how to filter `tax_query` by term meta instead `slug`/`id`?
```
function custom_pre_get_posts($query)
{
global $wp_query;
if ( !is_admin() && is_shop() && $query->is_main_query() && is_post_type_archive( "product" ))
{
$term = ???get_term_by_me... | Try This:
```
$args = array(
'hide_empty' => false, // also retrieve terms which are not used yet
'meta_query' => array(
array(
'key' => 'feature-group',
'value' => 'kitchen',
'compare' => 'LIKE'
)
),
'taxonomy' => 'category',
);
$terms = get_terms( $args );
``` |
231,229 | <p>I'm trying to determine if there's more than one page of comments in single.php. </p>
<p>In archive.php I can do something like this to check if there's more than one page of posts:</p>
<pre><code>if ( $wp_query->max_num_pages > 1 ) {
// There's more than one page of posts in this archive.
}
</code></pr... | [
{
"answer_id": 231237,
"author": "Ismail",
"author_id": 70833,
"author_profile": "https://wordpress.stackexchange.com/users/70833",
"pm_score": 1,
"selected": false,
"text": "<p>Try this, <code>get_option( 'page_comments' )</code> will check if pagination is checked in options > discussi... | 2016/07/01 | [
"https://wordpress.stackexchange.com/questions/231229",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/22599/"
] | I'm trying to determine if there's more than one page of comments in single.php.
In archive.php I can do something like this to check if there's more than one page of posts:
```
if ( $wp_query->max_num_pages > 1 ) {
// There's more than one page of posts in this archive.
}
```
As far as I can tell, this doesn... | *Just some additional info for the main comment query:*
Since you mentioned the global `$wp_query` object, we can see that it stores:
```
$wp_query->max_num_comment_pages = $comment_query->max_num_pages;
```
in the main comment query in the comments template.
There [exists a wrapper](https://codex.wordpress.org/Fu... |
231,251 | <p>I have a typical shortcode which prints some html on a page. The shortcode will only be used on pages where visitors are logged in.</p>
<p>As a separate operation, I've been using a custom field to trigger an action which performs that test and then does the redirect.</p>
<p>But I was wondering if it was possible ... | [
{
"answer_id": 231254,
"author": "Andy Macaulay-Brook",
"author_id": 94267,
"author_profile": "https://wordpress.stackexchange.com/users/94267",
"pm_score": 5,
"selected": true,
"text": "<p>Shortcode functions are only called when the content of the visual editor is processed and display... | 2016/07/02 | [
"https://wordpress.stackexchange.com/questions/231251",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17248/"
] | I have a typical shortcode which prints some html on a page. The shortcode will only be used on pages where visitors are logged in.
As a separate operation, I've been using a custom field to trigger an action which performs that test and then does the redirect.
But I was wondering if it was possible to combine that a... | Shortcode functions are only called when the content of the visual editor is processed and displayed, so nothing in your shortcode function will run early enough.
Have a look at the `has_shortcode` function. If you hook in early enough to send headers and late enough for the query to be set up you can check if the co... |
231,282 | <p>I can't find if WordPress stores the number of items in a menu. Basically I need to find out how many items are in a menu to work out the percentage each item should take up in the header bar. Is there a function? Or is the best way to achieve this doing something with <code>WP_Query</code>?</p>
| [
{
"answer_id": 231288,
"author": "birgire",
"author_id": 26350,
"author_profile": "https://wordpress.stackexchange.com/users/26350",
"pm_score": 4,
"selected": true,
"text": "<p>I was curious and decided to check it out, regardless if it's relevant for a CSS problem ;-)</p>\n\n<p>I first... | 2016/07/02 | [
"https://wordpress.stackexchange.com/questions/231282",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/75780/"
] | I can't find if WordPress stores the number of items in a menu. Basically I need to find out how many items are in a menu to work out the percentage each item should take up in the header bar. Is there a function? Or is the best way to achieve this doing something with `WP_Query`? | I was curious and decided to check it out, regardless if it's relevant for a CSS problem ;-)
I first peeked into the database tables to find more about the menu structure:
Menu - building blocks
----------------------
Each navigational menu is registered as a term in the `nav_menu` taxonomy.
Then when we add items ... |
231,296 | <p>A non-profit organisation (NPO) has a Wordpress website. The URL (example.com) carries the name of the NPO. The name of the NPO has changed so now we need to change the URL to reflect the new name. How do we do this, please?</p>
| [
{
"answer_id": 231309,
"author": "ido barnea",
"author_id": 97755,
"author_profile": "https://wordpress.stackexchange.com/users/97755",
"pm_score": 0,
"selected": false,
"text": "<p>If you already own name 2 as a domain,\nBuild your web site on it, and when you are done you can redirect ... | 2016/07/03 | [
"https://wordpress.stackexchange.com/questions/231296",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/97744/"
] | A non-profit organisation (NPO) has a Wordpress website. The URL (example.com) carries the name of the NPO. The name of the NPO has changed so now we need to change the URL to reflect the new name. How do we do this, please? | The easiest way is to use [search and replace for wordpress databases](https://interconnectit.com/products/search-and-replace-for-wordpress-databases/)
Then you should do a 301 redirect the old domain to the new domain to keep visitors and indexed in Google.
```
RewriteEngine On
RewriteCond %{HTTP_HOST} !^old-domain... |
231,327 | <p>How to configure .htaccess to this:
I need that my home page is <a href="http://mydomain.cl/c/news/" rel="nofollow">http://mydomain.cl/c/news/</a> but I cant do this.
Anyone want help me please?
Thanks!</p>
<p>Now, my htaccess is :</p>
<pre><code># BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
Re... | [
{
"answer_id": 231309,
"author": "ido barnea",
"author_id": 97755,
"author_profile": "https://wordpress.stackexchange.com/users/97755",
"pm_score": 0,
"selected": false,
"text": "<p>If you already own name 2 as a domain,\nBuild your web site on it, and when you are done you can redirect ... | 2016/07/03 | [
"https://wordpress.stackexchange.com/questions/231327",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/73011/"
] | How to configure .htaccess to this:
I need that my home page is <http://mydomain.cl/c/news/> but I cant do this.
Anyone want help me please?
Thanks!
Now, my htaccess is :
```
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
Re... | The easiest way is to use [search and replace for wordpress databases](https://interconnectit.com/products/search-and-replace-for-wordpress-databases/)
Then you should do a 301 redirect the old domain to the new domain to keep visitors and indexed in Google.
```
RewriteEngine On
RewriteCond %{HTTP_HOST} !^old-domain... |
231,348 | <p>I have a frustrating issue. I am using the <code>date_query</code> as referenced in the Codex: </p>
<pre><code><?php
$today = getdate();
$args = array(
'post_type' => 'Lighting',
'post_status' => 'publish',
'posts_per_page' => 1,
'date_query' => array(
array(
'yea... | [
{
"answer_id": 231309,
"author": "ido barnea",
"author_id": 97755,
"author_profile": "https://wordpress.stackexchange.com/users/97755",
"pm_score": 0,
"selected": false,
"text": "<p>If you already own name 2 as a domain,\nBuild your web site on it, and when you are done you can redirect ... | 2016/07/04 | [
"https://wordpress.stackexchange.com/questions/231348",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/97783/"
] | I have a frustrating issue. I am using the `date_query` as referenced in the Codex:
```
<?php
$today = getdate();
$args = array(
'post_type' => 'Lighting',
'post_status' => 'publish',
'posts_per_page' => 1,
'date_query' => array(
array(
'year' => $today['year'],
'mont... | The easiest way is to use [search and replace for wordpress databases](https://interconnectit.com/products/search-and-replace-for-wordpress-databases/)
Then you should do a 301 redirect the old domain to the new domain to keep visitors and indexed in Google.
```
RewriteEngine On
RewriteCond %{HTTP_HOST} !^old-domain... |
231,361 | <p>I am trying to create a custom post type. All are working fine except archive page. My custom post type archive page is archive-courses.php but is is not working it is showing default archive.php . Is there any wrong in my code? </p>
<p>Can anyone help me, please? </p>
<pre><code>function td_courses() {
$label... | [
{
"answer_id": 231365,
"author": "NateWr",
"author_id": 39309,
"author_profile": "https://wordpress.stackexchange.com/users/39309",
"pm_score": 3,
"selected": false,
"text": "<p>Your post type, <code>courses</code>, has a rewrite slug of <code>course</code>. So your archive template will... | 2016/07/04 | [
"https://wordpress.stackexchange.com/questions/231361",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/73498/"
] | I am trying to create a custom post type. All are working fine except archive page. My custom post type archive page is archive-courses.php but is is not working it is showing default archive.php . Is there any wrong in my code?
Can anyone help me, please?
```
function td_courses() {
$labels = array(
'n... | Your post type, `courses`, has a rewrite slug of `course`. So your archive template will be `archive-course.php`.
Your taxonomy, `courses_category`, has a rewrite slug of `course`, so your taxonomy archive template will be `taxonomy-courses.php`.
This complete [template hierarchy](https://developer.wordpress.org/them... |
231,362 | <p>Here I mentioned the url</p>
<pre><code>http://localhost/wp/2016/?category_name=cricket
</code></pre>
<p>now i need to rearrange the url like </p>
<pre><code>http://localhost/wp/cricket/2016.
</code></pre>
<p>here cricket is category name and 2016 is year.</p>
<p>Remove the ?Query String Variable not a value of... | [
{
"answer_id": 231365,
"author": "NateWr",
"author_id": 39309,
"author_profile": "https://wordpress.stackexchange.com/users/39309",
"pm_score": 3,
"selected": false,
"text": "<p>Your post type, <code>courses</code>, has a rewrite slug of <code>course</code>. So your archive template will... | 2016/07/04 | [
"https://wordpress.stackexchange.com/questions/231362",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/97782/"
] | Here I mentioned the url
```
http://localhost/wp/2016/?category_name=cricket
```
now i need to rearrange the url like
```
http://localhost/wp/cricket/2016.
```
here cricket is category name and 2016 is year.
Remove the ?Query String Variable not a value of the querystring in the wordpress URl.
I tried
```
Re... | Your post type, `courses`, has a rewrite slug of `course`. So your archive template will be `archive-course.php`.
Your taxonomy, `courses_category`, has a rewrite slug of `course`, so your taxonomy archive template will be `taxonomy-courses.php`.
This complete [template hierarchy](https://developer.wordpress.org/them... |
231,374 | <p>I need to get the comment author ID by the comment ID.</p>
<p><strong>Example</strong></p>
<pre><code>functionName($commentID){
return $authorID;
}
</code></pre>
| [
{
"answer_id": 231399,
"author": "jgraup",
"author_id": 84219,
"author_profile": "https://wordpress.stackexchange.com/users/84219",
"pm_score": 2,
"selected": false,
"text": "<p>Use <a href=\"https://codex.wordpress.org/Function_Reference/get_comment\" rel=\"nofollow\"><code>get_comment<... | 2016/07/04 | [
"https://wordpress.stackexchange.com/questions/231374",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/97801/"
] | I need to get the comment author ID by the comment ID.
**Example**
```
functionName($commentID){
return $authorID;
}
``` | Use [`get_comment`](https://codex.wordpress.org/Function_Reference/get_comment) to return information about the comment like `comment_author_email`.
You can then try to get a user by email using [`get_user_by`('email', $comment\_author\_email)](https://developer.wordpress.org/reference/functions/get_user_by/).
Once y... |
231,377 | <p>Why file <code>plugins/woocommerce/assets/css/woocommerce.css</code>
for my template can not be read?</p>
<p>Please look this image :</p>
<p><a href="https://i.stack.imgur.com/1miMt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1miMt.png" alt="enter image description here"></a></p>
| [
{
"answer_id": 231401,
"author": "Praveen",
"author_id": 97802,
"author_profile": "https://wordpress.stackexchange.com/users/97802",
"pm_score": 1,
"selected": false,
"text": "<pre><code>function woocommmerce_style() {\n wp_enqueue_style('woocommerce_stylesheet', WP_PLUGIN_URL. '/wooco... | 2016/07/04 | [
"https://wordpress.stackexchange.com/questions/231377",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/97803/"
] | Why file `plugins/woocommerce/assets/css/woocommerce.css`
for my template can not be read?
Please look this image :
[](https://i.stack.imgur.com/1miMt.png) | ```
function woocommmerce_style() {
wp_enqueue_style('woocommerce_stylesheet', WP_PLUGIN_URL. '/woocommerce/assets/css/woocommerce.css',false,'1.0',"all");
}
add_action( 'wp_head', 'woocommmerce_style' );
```
paste the above code in your "functions.php". woocommerce stylesheet will be executed to your site |
231,391 | <p>I have a site which uses Google's API's for jquery and a fallback for jquery. The problem is that I can't get the fallback to happen immediately after the jquery api attempt. What happens is that the fallback file is added after a range of plugin scripts which require jquery and then fails. How can I change the orde... | [
{
"answer_id": 231401,
"author": "Praveen",
"author_id": 97802,
"author_profile": "https://wordpress.stackexchange.com/users/97802",
"pm_score": 1,
"selected": false,
"text": "<pre><code>function woocommmerce_style() {\n wp_enqueue_style('woocommerce_stylesheet', WP_PLUGIN_URL. '/wooco... | 2016/07/04 | [
"https://wordpress.stackexchange.com/questions/231391",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/94998/"
] | I have a site which uses Google's API's for jquery and a fallback for jquery. The problem is that I can't get the fallback to happen immediately after the jquery api attempt. What happens is that the fallback file is added after a range of plugin scripts which require jquery and then fails. How can I change the order o... | ```
function woocommmerce_style() {
wp_enqueue_style('woocommerce_stylesheet', WP_PLUGIN_URL. '/woocommerce/assets/css/woocommerce.css',false,'1.0',"all");
}
add_action( 'wp_head', 'woocommmerce_style' );
```
paste the above code in your "functions.php". woocommerce stylesheet will be executed to your site |
231,394 | <p>I've got several search forms on my site and I want them to show different results. My website has a very strict hierarchy and the search form on a parent site should only show results from it's child pages.</p>
<p>My plan was to include different hidden fields on the different parent pages which contain the id of ... | [
{
"answer_id": 231408,
"author": "user1049961",
"author_id": 47664,
"author_profile": "https://wordpress.stackexchange.com/users/47664",
"pm_score": 1,
"selected": false,
"text": "<p>You can use <code>pre_get_posts</code> filter to filter out what you need. There's an example on how to d... | 2016/07/04 | [
"https://wordpress.stackexchange.com/questions/231394",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/93282/"
] | I've got several search forms on my site and I want them to show different results. My website has a very strict hierarchy and the search form on a parent site should only show results from it's child pages.
My plan was to include different hidden fields on the different parent pages which contain the id of that parti... | You can use `pre_get_posts` filter to filter out what you need. There's an example on how to do this in Codex:
<https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts#Exclude_Pages_from_Search_Results>
```
function search_filter($query) {
if ( !is_admin() && $query->is_main_query() ) {
if ($query... |
231,407 | <p>I am using the <a href="https://wordpress.org/plugins/wp-job-manager/" rel="nofollow">wp-job-manager plugin</a> and i want to add an Adsense code between the job listings ( after fifth job listing ) in the page with [jobs] shortcode.</p>
<p>The function that outputs the jobs resides in <a href="https://github.com/A... | [
{
"answer_id": 231409,
"author": "user1049961",
"author_id": 47664,
"author_profile": "https://wordpress.stackexchange.com/users/47664",
"pm_score": 1,
"selected": false,
"text": "<p>There's a filter for the output</p>\n\n<pre><code> $job_listings_output = apply_filters( 'job_manager_... | 2016/07/04 | [
"https://wordpress.stackexchange.com/questions/231407",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/96329/"
] | I am using the [wp-job-manager plugin](https://wordpress.org/plugins/wp-job-manager/) and i want to add an Adsense code between the job listings ( after fifth job listing ) in the page with [jobs] shortcode.
The function that outputs the jobs resides in [`class-wp-job-manager-shortcodes.php`](https://github.com/Automa... | There's a filter for the output
```
$job_listings_output = apply_filters( 'job_manager_job_listings_output', ob_get_clean() );
```
so, you should just do
```
add_filter('job_manager_job_listings_output','my_job_manager_job_listings_output');
function my_job_manager_job_listings_output($output) {
$adsense_cod... |
231,415 | <p>I have a contact form in a WordPress page like this:</p>
<pre><code>$( '#contact_form' ).bootstrapValidator({
fields: {
// ...
},
submitHandler: function( formInstance ) {
$.post( "../send-message", $("#contact_form").serialize(), function( result ) {
alert( pw_script_vars.S... | [
{
"answer_id": 231418,
"author": "user1049961",
"author_id": 47664,
"author_profile": "https://wordpress.stackexchange.com/users/47664",
"pm_score": 2,
"selected": false,
"text": "<p>You cannot use <code>wp_localize_script</code> in page template. You have to use it in <code>functions.ph... | 2016/07/04 | [
"https://wordpress.stackexchange.com/questions/231415",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/97480/"
] | I have a contact form in a WordPress page like this:
```
$( '#contact_form' ).bootstrapValidator({
fields: {
// ...
},
submitHandler: function( formInstance ) {
$.post( "../send-message", $("#contact_form").serialize(), function( result ) {
alert( pw_script_vars.State ); ... | You cannot use `wp_localize_script` in page template. You have to use it in `functions.php` or your custom plugin, after you register your script, which is usually in the `wp_enqueue_scripts` action.
<https://codex.wordpress.org/Function_Reference/wp_localize_script> |
231,424 | <p>If I'm just echoing regular text, I do this:</p>
<pre><code><?php _e('This post is closed to new comments.','my-theme') ?>
</code></pre>
<p>But how would I translate the text in <code>comments_number();</code> so that the "Comments" text can be translated? Like this:</p>
<pre><code><?php comments_number(... | [
{
"answer_id": 231426,
"author": "user1049961",
"author_id": 47664,
"author_profile": "https://wordpress.stackexchange.com/users/47664",
"pm_score": -1,
"selected": false,
"text": "<p>The <code>comments_number</code> function is calling <code>get_comments_number_text</code> function: <a ... | 2016/07/04 | [
"https://wordpress.stackexchange.com/questions/231424",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/91783/"
] | If I'm just echoing regular text, I do this:
```
<?php _e('This post is closed to new comments.','my-theme') ?>
```
But how would I translate the text in `comments_number();` so that the "Comments" text can be translated? Like this:
```
<?php comments_number( 'Comments (0)', 'Comments (1)', 'Comments (%)' ); ?>
``... | You have to make these strings translatable by using `__()` function:
```
comments_number( __('Comments (0)'), __('Comments (1)'), __('Comments (%)') );
```
If you want to use the custom `textdomain`, e.g. `'test'`:
```
comments_number( __('Comments (0)', 'test'), __('Comments (1)', 'test'), __('Comments (%)', 'tes... |
231,448 | <p>How to add dot(<code>.</code>) in post slugs?</p>
<p>In our blog, we are writing about websites and would like to use their exact address as slug like this:</p>
<p><code>ourdomain.com/<strong>example1.com</strong></code></p>
<p>But dots are either removed when a post is saved, or WordPress doesn't find the post w... | [
{
"answer_id": 231952,
"author": "Andy",
"author_id": 43719,
"author_profile": "https://wordpress.stackexchange.com/users/43719",
"pm_score": 3,
"selected": true,
"text": "<p>WordPress runs slugs through its <code>sanitize_title_with_dashes()</code> filter function which replaces dots wi... | 2016/07/05 | [
"https://wordpress.stackexchange.com/questions/231448",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/48647/"
] | How to add dot(`.`) in post slugs?
In our blog, we are writing about websites and would like to use their exact address as slug like this:
`ourdomain.com/**example1.com**`
But dots are either removed when a post is saved, or WordPress doesn't find the post when we successfully add one.
Is there any option available... | WordPress runs slugs through its `sanitize_title_with_dashes()` filter function which replaces dots with dashes. Unfortunately the function doesn't give you any control over that or any ability to change what characters are stripped or replaced.
What we can do however is remove that filter and add our own version of i... |
231,469 | <p>I basically need to change the date format to german date format all over the WordPress site and I succeed it by changing the date time settings from the WordPress admin panel.</p>
<blockquote>
<p><strong>Settings » General</strong> :</p>
<p><strong>Date Format</strong> - Custom : j. F Y</p>
<p>eg : 5.... | [
{
"answer_id": 231472,
"author": "Aipo",
"author_id": 67135,
"author_profile": "https://wordpress.stackexchange.com/users/67135",
"pm_score": 1,
"selected": false,
"text": "<p>Use locale in <code>wp-config.php</code> de_DE, language settings depends on admin panel language, it is possibl... | 2016/07/05 | [
"https://wordpress.stackexchange.com/questions/231469",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/68403/"
] | I basically need to change the date format to german date format all over the WordPress site and I succeed it by changing the date time settings from the WordPress admin panel.
>
> **Settings » General** :
>
>
> **Date Format** - Custom : j. F Y
>
>
> eg : 5. July 2016
>
>
>
However I need to change the month... | I have added the following code to child theme function and it works,
```
add_filter('the_time', 'modify_date_format');
function modify_date_format(){
$month_names = array(1=>'Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember');
return get_the_time('j').'.... |
231,479 | <p>I've inherited a very poorly designed WordPress site that in part uses BuddyPress for a directory type section. Users are able to upload profile images and 'product' images to their profile.</p>
<p>As a result, we now have roughly 20GB of images on the site and desperately need to cut back on this. When users, stop... | [
{
"answer_id": 231499,
"author": "Conor",
"author_id": 47324,
"author_profile": "https://wordpress.stackexchange.com/users/47324",
"pm_score": 0,
"selected": false,
"text": "<p>You would need to do a <code>SELECT</code> statement against the <code>wp_posts</code> and <code>wp_users</code... | 2016/07/05 | [
"https://wordpress.stackexchange.com/questions/231479",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/55152/"
] | I've inherited a very poorly designed WordPress site that in part uses BuddyPress for a directory type section. Users are able to upload profile images and 'product' images to their profile.
As a result, we now have roughly 20GB of images on the site and desperately need to cut back on this. When users, stop paying a ... | Here's some code which pulls all subscriber IDs, then pulls all attachments from those subscribers and attempts to delete them. If it can't delete them it'll write to the error log letting you know.
```
$subscribers = get_users( array(
'role' => 'subscriber',
'fields'=> 'ID',
) );
if( ! empty( $subscribers )... |
231,487 | <p>Okay, I've got the following issue. I'm trying to send a mail in HTML format. I made a class that returns an HTML string, and that works great.</p>
<p>When I pass that html-mail as $message in my function, works also. But it will not send as html, but plain text.</p>
<p>Now I've tried the following things:</p>
<p... | [
{
"answer_id": 231510,
"author": "Domain",
"author_id": 26523,
"author_profile": "https://wordpress.stackexchange.com/users/26523",
"pm_score": 1,
"selected": false,
"text": "<p>Try this one. </p>\n\n<pre><code> add_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' );... | 2016/07/05 | [
"https://wordpress.stackexchange.com/questions/231487",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/92815/"
] | Okay, I've got the following issue. I'm trying to send a mail in HTML format. I made a class that returns an HTML string, and that works great.
When I pass that html-mail as $message in my function, works also. But it will not send as html, but plain text.
Now I've tried the following things:
1)
`$headers = array('C... | Try this one.
```
add_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' );
$to = 'sendto@example.com';
$subject = 'The subject';
$body = 'The email body content';
$headers = array('Content-Type: text/html; charset=UTF-8');
wp_mail( $to, $subject, $body , $headers);
// Re... |
231,511 | <p>I am struggling to get my settings page to save my options. I've got it showing up correctly and it hits the sanitize function</p>
<pre><code> register_setting(
'my_options', // Option group
'my_settings', // Option name
array($this, 'sanitize') // Sanitize
);
</code></pre>
<p>When I... | [
{
"answer_id": 259603,
"author": "dhuyvetter",
"author_id": 86095,
"author_profile": "https://wordpress.stackexchange.com/users/86095",
"pm_score": 2,
"selected": false,
"text": "<p>It turned out to be nonce related: the form didn't have a nonce. Solved this by adding <code>wp_nonce_fiel... | 2016/07/05 | [
"https://wordpress.stackexchange.com/questions/231511",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/86095/"
] | I am struggling to get my settings page to save my options. I've got it showing up correctly and it hits the sanitize function
```
register_setting(
'my_options', // Option group
'my_settings', // Option name
array($this, 'sanitize') // Sanitize
);
```
When I run the debugger on the s... | It turned out to be nonce related: the form didn't have a nonce. Solved this by adding `wp_nonce_field` to the form. |
231,541 | <p>I have a wordpress website where I post song lyrics.
I have written a wp query to list specific posts and order them by post views. However, I would like to order them by youtube views instead.</p>
<p>I have been able to get the youtube view counts for the posts (songs), the problem is ordering the posts with it. T... | [
{
"answer_id": 250277,
"author": "Marco",
"author_id": 109575,
"author_profile": "https://wordpress.stackexchange.com/users/109575",
"pm_score": 4,
"selected": true,
"text": "<p>I've had the same problem, and in my case it was the Wordpress cronjob. I was calling the wp-cron.php as a roo... | 2016/07/05 | [
"https://wordpress.stackexchange.com/questions/231541",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/86102/"
] | I have a wordpress website where I post song lyrics.
I have written a wp query to list specific posts and order them by post views. However, I would like to order them by youtube views instead.
I have been able to get the youtube view counts for the posts (songs), the problem is ordering the posts with it. This is wha... | I've had the same problem, and in my case it was the Wordpress cronjob. I was calling the wp-cron.php as a root cron job, and this script also generates the monthly upload folder.
If you call wp-cron.php via cronjob you need to do this as the web server user (or i.e. in Plesk the site user and group psacln). The owner... |
231,548 | <p>I just learned about child themes recently and was wondering if creating a child theme for every theme I create is necessary. I just find it weird how other themes work okay without child themes, and others do not. </p>
| [
{
"answer_id": 231549,
"author": "Yarwood",
"author_id": 32655,
"author_profile": "https://wordpress.stackexchange.com/users/32655",
"pm_score": 1,
"selected": false,
"text": "<p>For me the rule of thumb is am I extending/revising an existing theme? If so I'll want to be able to update t... | 2016/07/05 | [
"https://wordpress.stackexchange.com/questions/231548",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/68815/"
] | I just learned about child themes recently and was wondering if creating a child theme for every theme I create is necessary. I just find it weird how other themes work okay without child themes, and others do not. | Child themes are not the only way to extend a theme, not even the best.
Many themes offer hooks: actions and filters. You can use these to change the output per plugin.
Let’s say you have a theme named *Acme*, and its `index.php` contains the following code:
```
get_header();
do_action( 'acme.loop.before', 'index' ... |
231,557 | <p>I'm trying to create a custom widget to display contributing authors for the current category being viewed on a WordPress site. I have the following PHP code:</p>
<pre><code><?php
if (is_category()) {
?>
// Grab posts from the current category
<?php
$current_category = single_cat_title(“”, false);
... | [
{
"answer_id": 231558,
"author": "Chinmoy Kumar Paul",
"author_id": 57436,
"author_profile": "https://wordpress.stackexchange.com/users/57436",
"pm_score": 0,
"selected": false,
"text": "<pre><code><?php\nif( is_category() ) {\n global $wp_query;\n $term_obj = $wp_query->get_quer... | 2016/07/06 | [
"https://wordpress.stackexchange.com/questions/231557",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/76765/"
] | I'm trying to create a custom widget to display contributing authors for the current category being viewed on a WordPress site. I have the following PHP code:
```
<?php
if (is_category()) {
?>
// Grab posts from the current category
<?php
$current_category = single_cat_title(“”, false);
$author_array = arr... | This can become a quite an expensive operation which can seriously damage page load time. At this stage, your code is quite expensive. Lets look a better way to tackle this issue.
What we need to do is to minimize the time spend in db, and to do this, we will only get the info we need, that is the `post_author` proper... |
231,589 | <p><br />
I've been trying to redirect a page but with no success. <br />
My purpose is to redirect <code>example.com/me/name</code> to <code>example.com/me?n=name</code><br />
I've tried with <code>add_rewrite_rule</code>, write conditions in .htaccess, but nothing worked.
Any clue?
<br/>
Edit:<br/>
The full htaccess ... | [
{
"answer_id": 231581,
"author": "cjbj",
"author_id": 75495,
"author_profile": "https://wordpress.stackexchange.com/users/75495",
"pm_score": 1,
"selected": false,
"text": "<p>This is an interesting question, though a bit too broad for a Q&A model. Here is what I would do:</p>\n\n<ol... | 2016/07/06 | [
"https://wordpress.stackexchange.com/questions/231589",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/97913/"
] | I've been trying to redirect a page but with no success.
My purpose is to redirect `example.com/me/name` to `example.com/me?n=name`
I've tried with `add_rewrite_rule`, write conditions in .htaccess, but nothing worked.
Any clue?
Edit:
The full htaccess code is this:
```
# BEGIN WordPress
<IfModule mod_rew... | I evaluated the different options and went with a plugin "Page Builder". While the technical aspects are not great (e.g. data persisting: all content gets serialized) is was the only option to give me enough flexibility and enough comfort so that the customer could make changes to the structure of each page.
Migrating... |
231,597 | <p>Following <a href="http://keithclark.co.uk/articles/loading-css-without-blocking-render/" rel="nofollow">Keith Clarks advice</a>, i'd like to load my fonts asynchronously. I try to achieve that by adding: </p>
<pre><code>wp_enqueue_style( 'font-awesome', URI . '/fonts/font-awesome/css/font-awesome.min.css' );
wp_st... | [
{
"answer_id": 231603,
"author": "bravokeyl",
"author_id": 43098,
"author_profile": "https://wordpress.stackexchange.com/users/43098",
"pm_score": 3,
"selected": false,
"text": "<p>We can use <a href=\"https://developer.wordpress.org/reference/hooks/style_loader_tag/\" rel=\"noreferrer\"... | 2016/07/06 | [
"https://wordpress.stackexchange.com/questions/231597",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/97916/"
] | Following [Keith Clarks advice](http://keithclark.co.uk/articles/loading-css-without-blocking-render/), i'd like to load my fonts asynchronously. I try to achieve that by adding:
```
wp_enqueue_style( 'font-awesome', URI . '/fonts/font-awesome/css/font-awesome.min.css' );
wp_style_add_data( 'font-awesome', 'onload', ... | We can use [`style_loader_tag`](https://developer.wordpress.org/reference/hooks/style_loader_tag/) filter to filter the link that is being output.
Here is the filter:
```
$tag = apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-css' $title href='$href' type='text/css' media='$media' />\n", $handle, $hr... |
231,623 | <p>A site I'm currently working on has a page structure like this</p>
<pre><code>About Us
|
|_People
| |
| _ Person 1
| _ Person 2
| _ Person 3
|... etc ...
</code></pre>
<p>Every 'Person' page is a separate page, but they all have the same structure using a few ACF fields to display a person's bio, photo etc.</p>... | [
{
"answer_id": 231625,
"author": "cjbj",
"author_id": 75495,
"author_profile": "https://wordpress.stackexchange.com/users/75495",
"pm_score": 2,
"selected": false,
"text": "<p>The easiest way would be to create a <a href=\"https://codex.wordpress.org/Post_Types#Custom_Post_Types\" rel=\"... | 2016/07/06 | [
"https://wordpress.stackexchange.com/questions/231623",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/37750/"
] | A site I'm currently working on has a page structure like this
```
About Us
|
|_People
| |
| _ Person 1
| _ Person 2
| _ Person 3
|... etc ...
```
Every 'Person' page is a separate page, but they all have the same structure using a few ACF fields to display a person's bio, photo etc.
I know how to create a custo... | You can always make use of the `page_template` filter to tell WordPress to use a specific page template for all child pages of a certain parent. It is as easy as creating a special page template, lets call it `page-wpse-person.php`.
Now it is as easy as including that template whenever a child page of `people` is bein... |
231,653 | <p>I'm recoding my website with custom post types to be better organized, have a better search experience and being able to hide some pages from other contributors, but I have a little problem.</p>
<p>I've set up a post type named <em>Files</em> which contains some files that my contributors should not see. Basically ... | [
{
"answer_id": 231812,
"author": "Faye",
"author_id": 76600,
"author_profile": "https://wordpress.stackexchange.com/users/76600",
"pm_score": 2,
"selected": true,
"text": "<p>From what I understand, you've got THREE options (updated).</p>\n<p><strong>Option 1: Dynamic Solution</strong> C... | 2016/07/06 | [
"https://wordpress.stackexchange.com/questions/231653",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/93282/"
] | I'm recoding my website with custom post types to be better organized, have a better search experience and being able to hide some pages from other contributors, but I have a little problem.
I've set up a post type named *Files* which contains some files that my contributors should not see. Basically the legal pages, ... | From what I understand, you've got THREE options (updated).
**Option 1: Dynamic Solution** Create categories for your custom post type - each category is going to have its own template.
You then create a single template that splits off based on category. Meaning you use the general header and footer in your single-po... |
231,685 | <p>I was wandering... All the translation functions (<code>__(), _e(), _x()</code> and so on) use the current/active language. Is there a way to get a translation from another language than the current one? For example, I'm on a French page and I want and english translation: how to?</p>
| [
{
"answer_id": 231888,
"author": "J.D.",
"author_id": 27757,
"author_profile": "https://wordpress.stackexchange.com/users/27757",
"pm_score": 2,
"selected": false,
"text": "<p>To find the answer to this question, you just need to look at how WordPress retrieves the translations. Ultimate... | 2016/07/07 | [
"https://wordpress.stackexchange.com/questions/231685",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/10381/"
] | I was wandering... All the translation functions (`__(), _e(), _x()` and so on) use the current/active language. Is there a way to get a translation from another language than the current one? For example, I'm on a French page and I want and english translation: how to? | So thanks to J.D., I finally ended up with this code:
```
function __2($string, $textdomain, $locale){
global $l10n;
if(isset($l10n[$textdomain])) $backup = $l10n[$textdomain];
load_textdomain($textdomain, get_template_directory() . '/languages/'. $locale . '.mo');
$translation = __($string,$textdomain);
if(... |
231,693 | <p>I am developing a theme with Underscores for WordPress. </p>
<p>When the user adds an image using the TinyMCE editor the following code is inserted: </p>
<pre><code><img class="wp-image-45 size-full aligncenter" src="http://example.com/wp-content/uploads/2016/06/process.png" alt="process" width="849" height="91... | [
{
"answer_id": 231695,
"author": "cjbj",
"author_id": 75495,
"author_profile": "https://wordpress.stackexchange.com/users/75495",
"pm_score": 2,
"selected": false,
"text": "<p>There's a filter called <a href=\"https://developer.wordpress.org/reference/hooks/image_send_to_editor/\" rel=\"... | 2016/07/07 | [
"https://wordpress.stackexchange.com/questions/231693",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/82713/"
] | I am developing a theme with Underscores for WordPress.
When the user adds an image using the TinyMCE editor the following code is inserted:
```
<img class="wp-image-45 size-full aligncenter" src="http://example.com/wp-content/uploads/2016/06/process.png" alt="process" width="849" height="91" />
```
When I look a... | As far as I know you could hook into the filter [`image_send_to_editor`](https://developer.wordpress.org/reference/hooks/image_send_to_editor/) like this:
```
function html5_insert_image($html, $id, $caption, $title, $align, $url) {
$url = wp_get_attachment_url($id);
$html5 = "<figure id='post-$id media-$id' clas... |
231,711 | <p>I have six regular categories, not custom (each category having between 5 and 10 posts) and I am trying to display one random post from each category on the page. </p>
<p>The problem with the output is getting the random posts is fine, but some posts are taken from the same category which I do not want. Here is the... | [
{
"answer_id": 231715,
"author": "cadobe",
"author_id": 58295,
"author_profile": "https://wordpress.stackexchange.com/users/58295",
"pm_score": 1,
"selected": false,
"text": "<p>I just fix it using bueltge sugestion such us:</p>\n\n<pre><code>foreach ( $cat_id_array as $cat ) :\n\n $a... | 2016/07/07 | [
"https://wordpress.stackexchange.com/questions/231711",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/58295/"
] | I have six regular categories, not custom (each category having between 5 and 10 posts) and I am trying to display one random post from each category on the page.
The problem with the output is getting the random posts is fine, but some posts are taken from the same category which I do not want. Here is the code I am... | Random ordering is quite expensive operations in SQL and can become a headache on very big sites. Getting a random post from a category for 6 categories will mean you might need to run 6 separate queries, each ordered randomly. This can really break the bank and leave you bankrupt.
From your answer and looking at the... |
231,815 | <p>Is there a way to remove styles added with wp_add_inline_style?</p>
<p>I noticed if I call wp_add_inline_style multiple times, it just keeps adding style, it does not overwrite what was added before.</p>
<p>The plugin is adding styles:</p>
<pre><code>$inline_css = '#selector{
color:red;
}';
wp_add_inline_styl... | [
{
"answer_id": 231820,
"author": "Ismail",
"author_id": 70833,
"author_profile": "https://wordpress.stackexchange.com/users/70833",
"pm_score": 2,
"selected": false,
"text": "<p>Looking into <code>wp-includes/class.wp-styles.php</code> core file I found a filter to use:</p>\n\n<pre><code... | 2016/07/08 | [
"https://wordpress.stackexchange.com/questions/231815",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/45321/"
] | Is there a way to remove styles added with wp\_add\_inline\_style?
I noticed if I call wp\_add\_inline\_style multiple times, it just keeps adding style, it does not overwrite what was added before.
The plugin is adding styles:
```
$inline_css = '#selector{
color:red;
}';
wp_add_inline_style($style, $inline_css)... | Remove styles added with `wp_add_inline_style()`
------------------------------------------------
If we want to keep the `custom-style-css` but only remove the `custom-style-inline-css`, then we can try e.g.
```
add_action( 'wp_print_styles', function()
{
// Remove previous inline style
wp_styles()->add_data(... |
231,816 | <p>I have created a simple plugin that locks down content for users not logged in and it is working fine. However any user on a multi-author site could use the same short code in his post to lock down content too. I do not want this to happen. </p>
<p>How may I restrict this functionality to administrators only?
This ... | [
{
"answer_id": 231818,
"author": "Ismail",
"author_id": 70833,
"author_profile": "https://wordpress.stackexchange.com/users/70833",
"pm_score": 0,
"selected": false,
"text": "<blockquote>\n <p>Fatal error: Call to undefined function wp_get_current_user()</p>\n</blockquote>\n\n<p>This ca... | 2016/07/08 | [
"https://wordpress.stackexchange.com/questions/231816",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/96667/"
] | I have created a simple plugin that locks down content for users not logged in and it is working fine. However any user on a multi-author site could use the same short code in his post to lock down content too. I do not want this to happen.
How may I restrict this functionality to administrators only?
This current co... | >
> Fatal error: Call to undefined function wp\_get\_current\_user()
>
>
>
This can be fixed by declaring `check_user_role` only when WP is ready, hooking into `wp` (to use WordPress functions and methods) or performing other workaround.
Simply check if `manage_options` capability is there for the user too ( or v... |
231,838 | <p>I have created custom page template. Now I have to make it configurable, however since I am using more than one template in my theme I would like to make sure that configuration will be available only when the user chooses this template for a page. Is there an option to do so? </p>
<p><code>add_meta_box</code> acce... | [
{
"answer_id": 231839,
"author": "tillinberlin",
"author_id": 26059,
"author_profile": "https://wordpress.stackexchange.com/users/26059",
"pm_score": 0,
"selected": false,
"text": "<p>\"<em>available only when user choose this template</em>\" ? I'm not sure (I doubt it) if this is even p... | 2016/07/09 | [
"https://wordpress.stackexchange.com/questions/231838",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/77480/"
] | I have created custom page template. Now I have to make it configurable, however since I am using more than one template in my theme I would like to make sure that configuration will be available only when the user chooses this template for a page. Is there an option to do so?
`add_meta_box` accepts different `$post_... | ```
<?
// Check:
// 1. If you are editing post, CPT, or page
// 2. If post type IS NOT SET
if( 'post.php' == basename($_SERVER['REQUEST_URI'], '?' . $_SERVER['QUERY_STRING']) && !isset($_GET['post_type']) ) {
// get post ID
$postid = $_GET['post'];
// check the template file name
if ('my_template.php... |
231,862 | <p>I am adding a function to the header:</p>
<pre><code>add_action('wp_head', 'mine');
function mine() {
global $authordata;
$avatar_url = get_avatar_ur($authordata->user_email);
// ....
}
</code></pre>
<p>But I am getting the error: <code>trying to get property of non-object</code>.
I guess this is because ... | [
{
"answer_id": 231876,
"author": "wpclevel",
"author_id": 92212,
"author_profile": "https://wordpress.stackexchange.com/users/92212",
"pm_score": 2,
"selected": false,
"text": "<p>The global <code>$authordata</code> variable is only available by default when <a href=\"https://core.trac.w... | 2016/07/09 | [
"https://wordpress.stackexchange.com/questions/231862",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98079/"
] | I am adding a function to the header:
```
add_action('wp_head', 'mine');
function mine() {
global $authordata;
$avatar_url = get_avatar_ur($authordata->user_email);
// ....
}
```
But I am getting the error: `trying to get property of non-object`.
I guess this is because I am in the header and not inside the po... | The global `$authordata` variable is only available by default when [`$wp_query->is_author() && isset($wp_query->post)` condition](https://core.trac.wordpress.org/browser/tags/4.5/src/wp-includes/class-wp.php#L583) is satisfied.
It means that you can't access `$authordata` inside a single post page.
You may try to ge... |
231,898 | <p>I'm using a WP plugin Called <a href="https://wordpress.org/plugins/search-filter/" rel="nofollow">Search and Filter</a> to filter a custom post type — a user directory.</p>
<p>The plugin lets a user filter the directory by specifying terms.</p>
<p>It will also let a user filter the directoy by MULTIPLE terms.</p>... | [
{
"answer_id": 231876,
"author": "wpclevel",
"author_id": 92212,
"author_profile": "https://wordpress.stackexchange.com/users/92212",
"pm_score": 2,
"selected": false,
"text": "<p>The global <code>$authordata</code> variable is only available by default when <a href=\"https://core.trac.w... | 2016/07/10 | [
"https://wordpress.stackexchange.com/questions/231898",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98107/"
] | I'm using a WP plugin Called [Search and Filter](https://wordpress.org/plugins/search-filter/) to filter a custom post type — a user directory.
The plugin lets a user filter the directory by specifying terms.
It will also let a user filter the directoy by MULTIPLE terms.
When it does so, I get a slug constructed lik... | The global `$authordata` variable is only available by default when [`$wp_query->is_author() && isset($wp_query->post)` condition](https://core.trac.wordpress.org/browser/tags/4.5/src/wp-includes/class-wp.php#L583) is satisfied.
It means that you can't access `$authordata` inside a single post page.
You may try to ge... |
231,901 | <p>I've tagged some products with 'tag1', 'tag2' or sometimes both.</p>
<p>I want to list the categories that contain products with a specific tag, so 'Cat1' will only be listed if it has a product that is tagged 'tag1'.</p>
| [
{
"answer_id": 231876,
"author": "wpclevel",
"author_id": 92212,
"author_profile": "https://wordpress.stackexchange.com/users/92212",
"pm_score": 2,
"selected": false,
"text": "<p>The global <code>$authordata</code> variable is only available by default when <a href=\"https://core.trac.w... | 2016/07/10 | [
"https://wordpress.stackexchange.com/questions/231901",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98112/"
] | I've tagged some products with 'tag1', 'tag2' or sometimes both.
I want to list the categories that contain products with a specific tag, so 'Cat1' will only be listed if it has a product that is tagged 'tag1'. | The global `$authordata` variable is only available by default when [`$wp_query->is_author() && isset($wp_query->post)` condition](https://core.trac.wordpress.org/browser/tags/4.5/src/wp-includes/class-wp.php#L583) is satisfied.
It means that you can't access `$authordata` inside a single post page.
You may try to ge... |
231,926 | <p>I'm dynamically generating my category post by getting the Page title and match it with the category name. The category I'm posting sometimes has a subcategory now I need to separate this subcategory by groups. I'm using this code. </p>
<pre><code><ul>
<?php
global $post;
$post_slug = get_the_titl... | [
{
"answer_id": 231928,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 1,
"selected": false,
"text": "<p>You can use <a href=\"https://codex.wordpress.org/Function_Reference/get_term_by\" rel=\"nofollow\"><code>get_term... | 2016/07/11 | [
"https://wordpress.stackexchange.com/questions/231926",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/62183/"
] | I'm dynamically generating my category post by getting the Page title and match it with the category name. The category I'm posting sometimes has a subcategory now I need to separate this subcategory by groups. I'm using this code.
```
<ul>
<?php
global $post;
$post_slug = get_the_title();
$args = array... | You can use [`get_term_by`](https://codex.wordpress.org/Function_Reference/get_term_by) to get a category by `name`-
```
$category = get_term_by( 'name', $post_slug, 'category' );
echo $category->term_id;
``` |
231,942 | <p>I am trying to access a single value from my database through my <code>functions.php</code>. I have tried three different ways to get a result using a dynamic ID and none have worked. I always get NULL as the response. Using a WP_query is not possibility here, so I need to solve this using SQL.</p>
<p><strong>Attem... | [
{
"answer_id": 231947,
"author": "Ehsaan",
"author_id": 54782,
"author_profile": "https://wordpress.stackexchange.com/users/54782",
"pm_score": 2,
"selected": false,
"text": "<p>I tested your all attempts in a shortcode:</p>\n\n<pre><code>function add_test_shortcode() {\n global $wpdb;\... | 2016/07/11 | [
"https://wordpress.stackexchange.com/questions/231942",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/25506/"
] | I am trying to access a single value from my database through my `functions.php`. I have tried three different ways to get a result using a dynamic ID and none have worked. I always get NULL as the response. Using a WP\_query is not possibility here, so I need to solve this using SQL.
**Attempt #1:**
```
global $pos... | Turns out all of my attempts were viable (Thanks ehsaan for also confirming). The issue was that I was trying to get data from a field that was empty at the time of the function. (I was creating a new/updated post that hadn't updated the field yet).
**Solution (delay the hook):**
```
// Time out the custom field to u... |
231,976 | <p>I want to add a new menu point to post that shows posts of a certain category. Adding a new page is easy if it is just a new post type. But I want to only show posts with a specific category and when updating posts make sure the category is checked.</p>
<p>IS there no way of doing this? I was hoping for some simple... | [
{
"answer_id": 231987,
"author": "Ivijan Stefan Stipić",
"author_id": 82023,
"author_profile": "https://wordpress.stackexchange.com/users/82023",
"pm_score": 0,
"selected": false,
"text": "<p>You can loop posts by category name or ID:</p>\n\n<pre><code>$query = new WP_Query( array( 'cate... | 2016/07/11 | [
"https://wordpress.stackexchange.com/questions/231976",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98158/"
] | I want to add a new menu point to post that shows posts of a certain category. Adding a new page is easy if it is just a new post type. But I want to only show posts with a specific category and when updating posts make sure the category is checked.
IS there no way of doing this? I was hoping for some simple functon, ... | You can filter the posts list by appending `?category_name=xx` to the admin posts list URL, and you can add a submenu page with that URL as the target via `add_submenu_page`:
```
add_action( 'admin_menu', 'wpd_admin_menu_item' );
function wpd_admin_menu_item(){
add_submenu_page(
'edit.php',
'Page t... |
231,995 | <p>I have a website that displays a slideshow using custom fields and the <a href="http://kenwheeler.github.io/slick/" rel="nofollow">Slick</a> carousel, using the code below. </p>
<pre><code> <?php $entries = get_post_meta( get_the_ID(), '_mysite_homepage_slider_group', true );
foreach ( (array) $entries ... | [
{
"answer_id": 232002,
"author": "slashbob",
"author_id": 54908,
"author_profile": "https://wordpress.stackexchange.com/users/54908",
"pm_score": -1,
"selected": false,
"text": "<p>Are all the if-statements that output html actually <em>inside</em> the checkbox if-statement? Can't really... | 2016/07/11 | [
"https://wordpress.stackexchange.com/questions/231995",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/52548/"
] | I have a website that displays a slideshow using custom fields and the [Slick](http://kenwheeler.github.io/slick/) carousel, using the code below.
```
<?php $entries = get_post_meta( get_the_ID(), '_mysite_homepage_slider_group', true );
foreach ( (array) $entries as $key => $entry ) {
$img = $... | There's some code missing from your question - the code where your slides are actually output.
The `foreach` loop you've posted only sets the variables, and the actual output happens below the loop.
So, all you're doing on the fourth slide is avoiding setting the variables... hence the slide is still output, but usin... |
232,029 | <p>I need help with my <code>query</code> that uses <code>rewind_posts</code> so that if a post is in a particular category, it moves to the top. What I would like to do is have a query that splits posts into a two-column page (left and right divs) and if a post is in a category called <code>First</code>, it's at the t... | [
{
"answer_id": 232057,
"author": "Pieter Goosen",
"author_id": 31545,
"author_profile": "https://wordpress.stackexchange.com/users/31545",
"pm_score": 1,
"selected": false,
"text": "<h2>REWORKED APPROACH</h2>\n\n<p>Due to this becoming a bit of tameletjie due to styling issues, lets rewo... | 2016/07/12 | [
"https://wordpress.stackexchange.com/questions/232029",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8049/"
] | I need help with my `query` that uses `rewind_posts` so that if a post is in a particular category, it moves to the top. What I would like to do is have a query that splits posts into a two-column page (left and right divs) and if a post is in a category called `First`, it's at the top of the list in the left column.
... | It's complete. This is my final code:
```
// the query. Only show posts that belong to the taxonomy called "post-status" and they have a slug called "post-status-published"
<?php $args = array('tax_query' => array(array('taxonomy' => 'post-status','field' => 'slug','terms' => array ('post-status-published')))); $query... |
232,038 | <p>We are running several sub-domain sites on a WordPress Multisite environment and want to switch the primary site from the root to a sub-domain like so:</p>
<p>Current site is <code>example.com</code> with <code>ID 1</code> (cannot rename because field is set and uneditable)</p>
<p>New site is <code>new.example.com... | [
{
"answer_id": 235578,
"author": "David",
"author_id": 31323,
"author_profile": "https://wordpress.stackexchange.com/users/31323",
"pm_score": 4,
"selected": false,
"text": "<p><del>Four years old and no answer? So here we go…-</del></p>\n\n<p>Let's take the following network setup as ex... | 2016/07/12 | [
"https://wordpress.stackexchange.com/questions/232038",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98186/"
] | We are running several sub-domain sites on a WordPress Multisite environment and want to switch the primary site from the root to a sub-domain like so:
Current site is `example.com` with `ID 1` (cannot rename because field is set and uneditable)
New site is `new.example.com` with `ID 15` (tried to rename to `example.... | ~~Four years old and no answer? So here we go…-~~
Let's take the following network setup as example (I'm using WP-CLI's [site list command](http://wp-cli.org/commands/site/list/)):
```
$ wp site list
+---------+--------------------+---------------------+---------------------+
| blog_id | url | last_upd... |
232,051 | <p>Many users do not compress or resize their images before uploading them into a post, so source images can often be a lot larger than the settings in /wp-admin/options-media.php.</p>
<p>Many theme and plugin authors do not respect the default settings in /wp-admin/options-media.php and often do not create custom siz... | [
{
"answer_id": 235578,
"author": "David",
"author_id": 31323,
"author_profile": "https://wordpress.stackexchange.com/users/31323",
"pm_score": 4,
"selected": false,
"text": "<p><del>Four years old and no answer? So here we go…-</del></p>\n\n<p>Let's take the following network setup as ex... | 2016/07/12 | [
"https://wordpress.stackexchange.com/questions/232051",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/1341/"
] | Many users do not compress or resize their images before uploading them into a post, so source images can often be a lot larger than the settings in /wp-admin/options-media.php.
Many theme and plugin authors do not respect the default settings in /wp-admin/options-media.php and often do not create custom sizes for thi... | ~~Four years old and no answer? So here we go…-~~
Let's take the following network setup as example (I'm using WP-CLI's [site list command](http://wp-cli.org/commands/site/list/)):
```
$ wp site list
+---------+--------------------+---------------------+---------------------+
| blog_id | url | last_upd... |
232,055 | <p>I want to get the list of all available hooks from active theme / from a specific plugin.</p>
<p>I was tried to get it from global variables <code>$wp_actions & $wp_filter</code> But, They are showing all registered hooks.</p>
<p>E.g.</p>
<pre><code>global $wp_actions, $wp_filter;
echo '<pre>';
print_r(... | [
{
"answer_id": 240532,
"author": "tivnet",
"author_id": 28961,
"author_profile": "https://wordpress.stackexchange.com/users/28961",
"pm_score": 3,
"selected": true,
"text": "<p>As of 2016-09-25, there is no ideal solution.</p>\n\n<p>The WP-Parser does the job, but you need to set up a sp... | 2016/07/12 | [
"https://wordpress.stackexchange.com/questions/232055",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/52167/"
] | I want to get the list of all available hooks from active theme / from a specific plugin.
I was tried to get it from global variables `$wp_actions & $wp_filter` But, They are showing all registered hooks.
E.g.
```
global $wp_actions, $wp_filter;
echo '<pre>';
print_r($wp_filter);
```
E.g. If theme or plugin regist... | As of 2016-09-25, there is no ideal solution.
The WP-Parser does the job, but you need to set up a special WP site to run it.
WooCommerce's `Hook-docs` is something much simpler, and can be easily tweaked.
I just wrote a long comment on the topic here:
<https://github.com/ApiGen/ApiGen/issues/307#issuecomment-249349... |
232,056 | <p>In the attached image, the posts are displayed in a slider style. When I click on post in the slider, suppose CArd5, then the details should of that post eg: the thumbnail, excerpt etc should be displayed in the pop-up, the pop-up html code has been included in the end as " "</p>
<pre><code>Function addcards()
... | [
{
"answer_id": 232065,
"author": "Neeraj Kumar",
"author_id": 98147,
"author_profile": "https://wordpress.stackexchange.com/users/98147",
"pm_score": -1,
"selected": false,
"text": "<p>there are many ways to this but i suggest ajax for it. When you click on any post get the post_id and p... | 2016/07/12 | [
"https://wordpress.stackexchange.com/questions/232056",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/97552/"
] | In the attached image, the posts are displayed in a slider style. When I click on post in the slider, suppose CArd5, then the details should of that post eg: the thumbnail, excerpt etc should be displayed in the pop-up, the pop-up html code has been included in the end as " "
```
Function addcards()
{
$the_q... | I am giving you an idea for this, you have to use jQuery for the popup and the below syntax will give you the current post data in a HTML popup.
```
while ($the_query->have_posts()): $the_query->the_post();
echo '<div class="non-popup">';
echo '<div class="card-title" id="card-'.get_the_title.'"... |
232,080 | <p>We have user profile page in frontend. We need to add functionality to user add their profile image from profile page in frontend. </p>
<p>Is any plugin or custom functions available for that ? </p>
| [
{
"answer_id": 232065,
"author": "Neeraj Kumar",
"author_id": 98147,
"author_profile": "https://wordpress.stackexchange.com/users/98147",
"pm_score": -1,
"selected": false,
"text": "<p>there are many ways to this but i suggest ajax for it. When you click on any post get the post_id and p... | 2016/07/12 | [
"https://wordpress.stackexchange.com/questions/232080",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98209/"
] | We have user profile page in frontend. We need to add functionality to user add their profile image from profile page in frontend.
Is any plugin or custom functions available for that ? | I am giving you an idea for this, you have to use jQuery for the popup and the below syntax will give you the current post data in a HTML popup.
```
while ($the_query->have_posts()): $the_query->the_post();
echo '<div class="non-popup">';
echo '<div class="card-title" id="card-'.get_the_title.'"... |
232,091 | <p>I recently started wp development and am trying to make a website on the Wonderflux framework. </p>
<p>Currently, I set the homepage as a static page from the WP admin dashboard. Now I am currently editing said page inside wp.</p>
<p><a href="https://i.stack.imgur.com/O9yza.png" rel="nofollow noreferrer"><img src=... | [
{
"answer_id": 232065,
"author": "Neeraj Kumar",
"author_id": 98147,
"author_profile": "https://wordpress.stackexchange.com/users/98147",
"pm_score": -1,
"selected": false,
"text": "<p>there are many ways to this but i suggest ajax for it. When you click on any post get the post_id and p... | 2016/07/12 | [
"https://wordpress.stackexchange.com/questions/232091",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98213/"
] | I recently started wp development and am trying to make a website on the Wonderflux framework.
Currently, I set the homepage as a static page from the WP admin dashboard. Now I am currently editing said page inside wp.
[](https://i.stack.imgur.com/O9yza.png)
Is this th... | I am giving you an idea for this, you have to use jQuery for the popup and the below syntax will give you the current post data in a HTML popup.
```
while ($the_query->have_posts()): $the_query->the_post();
echo '<div class="non-popup">';
echo '<div class="card-title" id="card-'.get_the_title.'"... |
232,104 | <p>so I am hoping to retrieve a custom field that is already displayed on the "front-page.php" template on an another page.php template of my website. I know how to do that with the post-id way, but what I'm hoping to do is get it so that it automatically retrieves them from the front page template... the reason why I ... | [
{
"answer_id": 232105,
"author": "user319940",
"author_id": 24044,
"author_profile": "https://wordpress.stackexchange.com/users/24044",
"pm_score": 1,
"selected": false,
"text": "<pre><code>$val = get_post_meta( get_the_ID(), 'meta_data_name', true );\necho $val;\n</code></pre>\n\n<p>You... | 2016/07/12 | [
"https://wordpress.stackexchange.com/questions/232104",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/58060/"
] | so I am hoping to retrieve a custom field that is already displayed on the "front-page.php" template on an another page.php template of my website. I know how to do that with the post-id way, but what I'm hoping to do is get it so that it automatically retrieves them from the front page template... the reason why I wan... | ```
$val = get_post_meta( get_the_ID(), 'meta_data_name', true );
echo $val;
```
You can replace get\_the\_ID() with the ID of the post you are getting the meta from.
You could possible team this with:
```
$frontpage_id = get_option('page_on_front');
```
to get the homepage ID. Not sure if this would be friendly ... |
232,115 | <p>I am in the process of rewriting a lot of my code and restructuring a lot of my theme files to use template parts (i.e. using <code>get_template_part()</code>). I've come upon a situation where I want to use the same template parts whether I'm using the main query or a secondary custom query (using <code>WP_Query</c... | [
{
"answer_id": 232117,
"author": "Howdy_McGee",
"author_id": 7355,
"author_profile": "https://wordpress.stackexchange.com/users/7355",
"pm_score": 1,
"selected": false,
"text": "<p>I feel like you should be using <code>get_template_part()</code> for markup. Let's say you have a Custom Te... | 2016/07/12 | [
"https://wordpress.stackexchange.com/questions/232115",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/81652/"
] | I am in the process of rewriting a lot of my code and restructuring a lot of my theme files to use template parts (i.e. using `get_template_part()`). I've come upon a situation where I want to use the same template parts whether I'm using the main query or a secondary custom query (using `WP_Query`). The template parts... | In general, I agree with Howdy\_McGee that one should avoid overwriting the main query unless absolutely necessary - more often than not, modifying the main query with something like a `'pre_get_posts'` hook is a better solution to such scenarios.
Manually overwriting the global `$wp_query` can cause all sorts of unin... |
232,127 | <p>I have been trying to make a sign-out plugin that allows users to sign out from military training activities that they should be at. After they fill out a form explaining why they are not going to be at an activity, they submit it, and it puts all the data into a mysql database. I am trying to save the user's id to ... | [
{
"answer_id": 232128,
"author": "Ehsaan",
"author_id": 54782,
"author_profile": "https://wordpress.stackexchange.com/users/54782",
"pm_score": 0,
"selected": false,
"text": "<p>You can get current user ID easily using <code>get_current_user_id()</code>.</p>\n\n<pre><code>$usersid = get_... | 2016/07/13 | [
"https://wordpress.stackexchange.com/questions/232127",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98239/"
] | I have been trying to make a sign-out plugin that allows users to sign out from military training activities that they should be at. After they fill out a form explaining why they are not going to be at an activity, they submit it, and it puts all the data into a mysql database. I am trying to save the user's id to the... | Try this.
If no user are signed in then wp\_get\_current\_user get fatal error so your plugin breaks. But if you want only user id then use get\_current\_user\_id.
If no user signed in then it will return 0. So your plugin will not break.
Thanks
```
function f2user() {
// Get the current user's info
$current_... |
232,135 | <p>I am new to word press but know all the required PHP skills.
I am using a form to create session in one page and then accessing those sessions in another page. I have done this already without word press. What i need is someone tells me how to do this in word press. what files i have to change in word press, which c... | [
{
"answer_id": 232137,
"author": "TomC",
"author_id": 36980,
"author_profile": "https://wordpress.stackexchange.com/users/36980",
"pm_score": 1,
"selected": false,
"text": "<p>You want to use the init hook to start the session such as:</p>\n\n<pre><code>function start_session() {\n if... | 2016/07/13 | [
"https://wordpress.stackexchange.com/questions/232135",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98132/"
] | I am new to word press but know all the required PHP skills.
I am using a form to create session in one page and then accessing those sessions in another page. I have done this already without word press. What i need is someone tells me how to do this in word press. what files i have to change in word press, which code... | TomC is right, but to build on that here's what I do. Mainly I use this with a global object which I serialise into the session to save and unserialise from the session to use. Here I've just used an array of your variables. This way you don't need to worry about saving into the session as you go and the session use is... |
232,152 | <p>I have marked the option - " Users must be registered and logged in to comment " in Admin panel Setting -> Discussion section but i want only subscriber role user can comment not other roles type user.</p>
<p>Thanks,</p>
| [
{
"answer_id": 232154,
"author": "pallavi",
"author_id": 96726,
"author_profile": "https://wordpress.stackexchange.com/users/96726",
"pm_score": 0,
"selected": false,
"text": "<p>The below code check if user is not subscriber then comment form will not display. Comment form only show whe... | 2016/07/13 | [
"https://wordpress.stackexchange.com/questions/232152",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/89896/"
] | I have marked the option - " Users must be registered and logged in to comment " in Admin panel Setting -> Discussion section but i want only subscriber role user can comment not other roles type user.
Thanks, | I suggest adding a snippet to the theme file where the comments form is loaded that checks to make sure there is a logged in user and then, if that user a Subscriber, then show the comments form to them. The examples below use the Twenty Sixteen theme:
In comments.php:
```
// First, get the current user and check the... |
232,164 | <p>I have created custom fields on my registration form, such as 'telephone', using <a href="https://wordpress.org/plugins/theme-my-login/" rel="nofollow">Theme My Login</a>. I have found a way to make them appear in the backend (on the User page) but I can't update those fields.</p>
<p>What do I need to do in order t... | [
{
"answer_id": 232166,
"author": "shubham jain",
"author_id": 89896,
"author_profile": "https://wordpress.stackexchange.com/users/89896",
"pm_score": 0,
"selected": false,
"text": "<p>You can use the following function to update custom field value for user </p>\n\n<pre><code> update_u... | 2016/07/13 | [
"https://wordpress.stackexchange.com/questions/232164",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/97014/"
] | I have created custom fields on my registration form, such as 'telephone', using [Theme My Login](https://wordpress.org/plugins/theme-my-login/). I have found a way to make them appear in the backend (on the User page) but I can't update those fields.
What do I need to do in order to be able to update them?
Register-... | I use [update\_user\_meta](https://codex.wordpress.org/Function_Reference/update_user_meta) to update the fields. You can add this in functions.php of your child theme.
```
function save_extra_user_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) ) {
return false;
}
update_user_meta... |
232,174 | <p>I need to change default WordPress <code>get_custom_logo()</code> generated url because I need to link to the main multi-site site instead of single site. Is there any filter to change this function?</p>
| [
{
"answer_id": 232175,
"author": "Davide De Maestri",
"author_id": 8741,
"author_profile": "https://wordpress.stackexchange.com/users/8741",
"pm_score": 3,
"selected": false,
"text": "<p>I solved using this filter:</p>\n\n<pre><code>add_filter( 'get_custom_logo', 'custom_logo_url' );\nf... | 2016/07/13 | [
"https://wordpress.stackexchange.com/questions/232174",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/8741/"
] | I need to change default WordPress `get_custom_logo()` generated url because I need to link to the main multi-site site instead of single site. Is there any filter to change this function? | I solved using this filter:
```
add_filter( 'get_custom_logo', 'custom_logo_url' );
function custom_logo_url ( $html ) {
$custom_logo_id = get_theme_mod( 'custom_logo' );
$url = network_site_url();
$html = sprintf( '<a href="%1$s" class="custom-logo-link" rel="home" itemprop="url">%2$s</a>',
esc_url( $url )... |
232,185 | <p>I have a fairly simple AJAX request for my WordPress site. My PHP function is a switch statement and all the other switch statements work except for the recent one I added (change_due_date).</p>
<p>I commented out the majority of the code in my new 'case' to better try to find the problem. </p>
<p>AJAX (at bottom ... | [
{
"answer_id": 232219,
"author": "scott",
"author_id": 93587,
"author_profile": "https://wordpress.stackexchange.com/users/93587",
"pm_score": 0,
"selected": false,
"text": "<p>I think you may have a problem in the way you establish your data. If you read the WP Codex on AJAX, you will s... | 2016/07/13 | [
"https://wordpress.stackexchange.com/questions/232185",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/97928/"
] | I have a fairly simple AJAX request for my WordPress site. My PHP function is a switch statement and all the other switch statements work except for the recent one I added (change\_due\_date).
I commented out the majority of the code in my new 'case' to better try to find the problem.
AJAX (at bottom of page, under ... | A simple answer to your question is that you have the data type as JSON in your ajax request and you are passing a string in it. You need to pass a json object in the ajax request when you chose dataType equals to JSON. A JSON object is typically a key pair value inside curly braces. Here is a reference where you can s... |
232,193 | <p>I have a custom post type called location. I would like to be able to use 2 different templates for this custom post type and select it via the page attributes box. I have a template set up and can select it when I'm editing a Page, but not when I am editing a custom post type. I can't find any information on how to... | [
{
"answer_id": 232238,
"author": "MrFox",
"author_id": 69240,
"author_profile": "https://wordpress.stackexchange.com/users/69240",
"pm_score": 0,
"selected": false,
"text": "<p>Ok as mmm has pointed out that I can't do the dropdown select of templates on custom post types I have put this... | 2016/07/13 | [
"https://wordpress.stackexchange.com/questions/232193",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/69240/"
] | I have a custom post type called location. I would like to be able to use 2 different templates for this custom post type and select it via the page attributes box. I have a template set up and can select it when I'm editing a Page, but not when I am editing a custom post type. I can't find any information on how to en... | Since WordPress version 4.7 **Post-Type-Templates are enabled** in the WordPress core.
That means that you can **create multiple templates for the single post-type view** as for pages.
For this you just need to edit the single post/type template, and add something like this to the top of the file:
```
/*
Template N... |
232,201 | <p>We are developing WordPress with multiple site. We need to share some posts to more than one site. We need to save post in more than one sites with a single click. </p>
<p>I have searched in Google, but I can't get any tutorial for that. </p>
| [
{
"answer_id": 232238,
"author": "MrFox",
"author_id": 69240,
"author_profile": "https://wordpress.stackexchange.com/users/69240",
"pm_score": 0,
"selected": false,
"text": "<p>Ok as mmm has pointed out that I can't do the dropdown select of templates on custom post types I have put this... | 2016/07/13 | [
"https://wordpress.stackexchange.com/questions/232201",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98283/"
] | We are developing WordPress with multiple site. We need to share some posts to more than one site. We need to save post in more than one sites with a single click.
I have searched in Google, but I can't get any tutorial for that. | Since WordPress version 4.7 **Post-Type-Templates are enabled** in the WordPress core.
That means that you can **create multiple templates for the single post-type view** as for pages.
For this you just need to edit the single post/type template, and add something like this to the top of the file:
```
/*
Template N... |
232,246 | <p>Clicking the <strong>Update Profile</strong> button in the</p>
<pre><code>[wordpress]/wp-admin/profile.php
</code></pre>
<p>admin screen will allow the user to update his/her profile including the password.</p>
<p>What is the right action hook to use if you want to capture the new password during this password ch... | [
{
"answer_id": 232300,
"author": "Ismail",
"author_id": 70833,
"author_profile": "https://wordpress.stackexchange.com/users/70833",
"pm_score": 1,
"selected": false,
"text": "<p>I have been looking around the core files searching for hooks, there were very few when it comes to hooking in... | 2016/07/14 | [
"https://wordpress.stackexchange.com/questions/232246",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/58915/"
] | Clicking the **Update Profile** button in the
```
[wordpress]/wp-admin/profile.php
```
admin screen will allow the user to update his/her profile including the password.
What is the right action hook to use if you want to capture the new password during this password change? | I have been looking around the core files searching for hooks, there were very few when it comes to hooking into `edit_user()` function which updates the user data in `profile.php` page, so I have finished with some workarounds:
My workaround is to save the user's password in a custom option before the password was up... |
232,249 | <p>I am new to Wordpress but I have some knowledge of PHP. I am creating a bilingual site (with Polylang) which has many forms. Some of them are handled by Contact Form 7 but some others have to be custom made.</p>
<p>So, the first form I made was quite a disaster - it works but under certain circumstances. </p>
<p>I... | [
{
"answer_id": 232300,
"author": "Ismail",
"author_id": 70833,
"author_profile": "https://wordpress.stackexchange.com/users/70833",
"pm_score": 1,
"selected": false,
"text": "<p>I have been looking around the core files searching for hooks, there were very few when it comes to hooking in... | 2016/07/14 | [
"https://wordpress.stackexchange.com/questions/232249",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98314/"
] | I am new to Wordpress but I have some knowledge of PHP. I am creating a bilingual site (with Polylang) which has many forms. Some of them are handled by Contact Form 7 but some others have to be custom made.
So, the first form I made was quite a disaster - it works but under certain circumstances.
In the archives pa... | I have been looking around the core files searching for hooks, there were very few when it comes to hooking into `edit_user()` function which updates the user data in `profile.php` page, so I have finished with some workarounds:
My workaround is to save the user's password in a custom option before the password was up... |
232,254 | <p><br/>
Is there a way to check that comment was successfully submitted? I want to display some text or hide a comment form for example if comment was succesfully submitted. </p>
| [
{
"answer_id": 232300,
"author": "Ismail",
"author_id": 70833,
"author_profile": "https://wordpress.stackexchange.com/users/70833",
"pm_score": 1,
"selected": false,
"text": "<p>I have been looking around the core files searching for hooks, there were very few when it comes to hooking in... | 2016/07/14 | [
"https://wordpress.stackexchange.com/questions/232254",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/97934/"
] | Is there a way to check that comment was successfully submitted? I want to display some text or hide a comment form for example if comment was succesfully submitted. | I have been looking around the core files searching for hooks, there were very few when it comes to hooking into `edit_user()` function which updates the user data in `profile.php` page, so I have finished with some workarounds:
My workaround is to save the user's password in a custom option before the password was up... |
232,269 | <p>I've spent a day or so on this now and I'm turning to the community for assistance.</p>
<p>Firstly, I am trying to achieve something like this post:</p>
<p><a href="https://wordpress.stackexchange.com/questions/27158/wordpress-multiple-category-search">Wordpress Multiple Category Search</a></p>
<p>In my theme tem... | [
{
"answer_id": 232270,
"author": "Preethi Sasankan",
"author_id": 92003,
"author_profile": "https://wordpress.stackexchange.com/users/92003",
"pm_score": 2,
"selected": false,
"text": "<p><strong>let’s start by defining an HTML search form:</strong></p>\n\n<pre><code><form method=\"ge... | 2016/07/14 | [
"https://wordpress.stackexchange.com/questions/232269",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98327/"
] | I've spent a day or so on this now and I'm turning to the community for assistance.
Firstly, I am trying to achieve something like this post:
[Wordpress Multiple Category Search](https://wordpress.stackexchange.com/questions/27158/wordpress-multiple-category-search)
In my theme template, I have a custom search form:... | Here is what worked for me.
Preethis answer almost got there, but no data was getting set. I needed to find a way of accessing the data in the array, and I used implode to do it.
So here is my final code that enabled me to create a search form that loops and displays categories, allows the user to do a keyword search... |
232,278 | <p>I have a plugin that reads data from an uploaded file and runs queries on the wp database. These inserts are into a table created by my plugin, so they aren't the post type.</p>
<p>This is how I got it working: </p>
<pre><code>$connection = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
mysqli_query($conn... | [
{
"answer_id": 232284,
"author": "Sabbir Hasan",
"author_id": 76587,
"author_profile": "https://wordpress.stackexchange.com/users/76587",
"pm_score": 3,
"selected": false,
"text": "<p>Why not study about how <strong>$wpdb</strong> works. Visit <a href=\"https://codex.wordpress.org/Class_... | 2016/07/14 | [
"https://wordpress.stackexchange.com/questions/232278",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98214/"
] | I have a plugin that reads data from an uploaded file and runs queries on the wp database. These inserts are into a table created by my plugin, so they aren't the post type.
This is how I got it working:
```
$connection = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
mysqli_query($connection, $query);
```... | That's not a good practice trying to connect the DB by your own methods while WP does it for you initially.
---
>
> The problem with this is that I have to declare these variables
> ($db\_host, $db\_user, $db\_pass, $db\_name) inside the plugin source
> code.
>
>
>
All these properties are defined in `wp-confi... |
232,308 | <p>I made a plugin that adds a shortcode with optional content. If there's no content, WordPress still tries looking for a closing tag. This is clearer with an example:</p>
<pre><code>[span class="foo"]
[span class="bar"]
[span class="baz"]stuff[/span]
</code></pre>
<p>Wanted:</p>
<pre><code><span class="foo">... | [
{
"answer_id": 232332,
"author": "webHasan",
"author_id": 44137,
"author_profile": "https://wordpress.stackexchange.com/users/44137",
"pm_score": 3,
"selected": false,
"text": "<p>Wordpress interpreted your shortcode like this:</p>\n\n<p><a href=\"https://i.stack.imgur.com/4S0P0.png\" re... | 2016/07/15 | [
"https://wordpress.stackexchange.com/questions/232308",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/23538/"
] | I made a plugin that adds a shortcode with optional content. If there's no content, WordPress still tries looking for a closing tag. This is clearer with an example:
```
[span class="foo"]
[span class="bar"]
[span class="baz"]stuff[/span]
```
Wanted:
```
<span class="foo"></span>
<span class="bar"></span>
<span cla... | Wordpress interpreted your shortcode like this:
[](https://i.stack.imgur.com/4S0P0.png)
The main issue being, that you have a unclosed shortcode of the same tag in front of an enclosing shortcode of the same tag, which won't be parsed correc... |
232,345 | <p>I have PHP code</p>
<pre><code><?php if ($_SESSION['logged_in'] == 1) {
echo '<script type="text/javascript">var logged_in=true;</script>';
} else {
echo '<script type="text/javascript">var logged_in=false;</script>';
}?>
</code></pre>
<p>It always returns <code>var logged_in=... | [
{
"answer_id": 232346,
"author": "Александр",
"author_id": 88709,
"author_profile": "https://wordpress.stackexchange.com/users/88709",
"pm_score": 2,
"selected": false,
"text": "<pre><code><?php\nif ( is_user_logged_in() ) {\n echo '<script type=\"text/javascript\">var logged_i... | 2016/07/15 | [
"https://wordpress.stackexchange.com/questions/232345",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/88709/"
] | I have PHP code
```
<?php if ($_SESSION['logged_in'] == 1) {
echo '<script type="text/javascript">var logged_in=true;</script>';
} else {
echo '<script type="text/javascript">var logged_in=false;</script>';
}?>
```
It always returns `var logged_in=false;`. Where is mistake? | ```
<?php
if ( is_user_logged_in() ) {
echo '<script type="text/javascript">var logged_in=true;</script>';
} else {
echo '<script type="text/javascript">var logged_in=false;</script>';
}
?>
``` |
232,409 | <p>There is a major problem with most new templates for WordPress that want you to set your homepage to <strong><code>Your Latest Posts</code></strong>. </p>
<p>This is to enable many of the great theme features to work.</p>
<p>The problem with this is that the front page (even though not a blog page) is seen as a pa... | [
{
"answer_id": 232410,
"author": "mlimon",
"author_id": 64458,
"author_profile": "https://wordpress.stackexchange.com/users/64458",
"pm_score": 0,
"selected": false,
"text": "<p>I see you already tried with wpseo_next_rel_link can try with this one more time.</p>\n\n<pre><code>function w... | 2016/07/16 | [
"https://wordpress.stackexchange.com/questions/232409",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98424/"
] | There is a major problem with most new templates for WordPress that want you to set your homepage to **`Your Latest Posts`**.
This is to enable many of the great theme features to work.
The problem with this is that the front page (even though not a blog page) is seen as a paged entity by the wordpress core and yoas... | Here is the answer:
```
function bg_disable_front_page_wpseo_next_rel_link( $link ) {
if ( is_front_page() ) {
return false;
}
return $link;
}
add_filter( 'wpseo_next_rel_link', 'bg_disable_front_page_wpseo_next_rel_link' );
```
You have to return the $link, if you return nothing it will disable... |
232,435 | <p>I need some customization of WORDPRESS comment area, so I've used this code in my child theme :</p>
<pre><code> <div id="comments" class="x-comments-area">
<?php if ( have_comments() ) : ?>
<?php
//The author of current post
$author_ID = get_the_author_meta("ID");
//The curre... | [
{
"answer_id": 232460,
"author": "JMau",
"author_id": 31376,
"author_profile": "https://wordpress.stackexchange.com/users/31376",
"pm_score": 1,
"selected": false,
"text": "<p>This notice comes because object <code>$comments</code> is null. So the <code>have_comments()</code> must wrap a... | 2016/07/17 | [
"https://wordpress.stackexchange.com/questions/232435",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/62437/"
] | I need some customization of WORDPRESS comment area, so I've used this code in my child theme :
```
<div id="comments" class="x-comments-area">
<?php if ( have_comments() ) : ?>
<?php
//The author of current post
$author_ID = get_the_author_meta("ID");
//The current post ID
$p_ID = get_th... | This notice comes because object `$comments` is null. So the `have_comments()` must wrap all the thing to be sure there are comments before using any property.
in your case :
```
<?php if ( have_comments() ) :
/* the code */
endif; ?>
``` |
232,436 | <p>So recently I moved a client from Blogger to Wordpress.</p>
<p>When the posts imported from blogger, it saved the blogger "labels" as "tags" in Wordpress. Since I'd like to have these as categories instead, I used a plugin to convert all tags to categories.</p>
<p>This worked fine and dandy, but it left Uncategori... | [
{
"answer_id": 232441,
"author": "Simon Cossar",
"author_id": 59349,
"author_profile": "https://wordpress.stackexchange.com/users/59349",
"pm_score": 3,
"selected": false,
"text": "<p>With <a href=\"https://wp-cli.org/\">wp-cli</a> installed you can run a bash script like this to remove ... | 2016/07/17 | [
"https://wordpress.stackexchange.com/questions/232436",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/75134/"
] | So recently I moved a client from Blogger to Wordpress.
When the posts imported from blogger, it saved the blogger "labels" as "tags" in Wordpress. Since I'd like to have these as categories instead, I used a plugin to convert all tags to categories.
This worked fine and dandy, but it left Uncategorized on all of my ... | With [wp-cli](https://wp-cli.org/) installed you can run a bash script like this to remove the 'uncategorized' category from all posts with more than one category
```
#!/bin/bash
for post in $(wp post list --field=ID)
do
count=$(wp post term list $post 'category' --fields='name' --format="count")
if [ "$count" -g... |
232,462 | <p>I'm trying to return only pages in search results.</p>
<p>This is working:</p>
<p><code>/?s=term&post_type=post</code></p>
<p>It returns only posts, no pages.</p>
<p>But the opposite is not working:</p>
<p><code>/?s=term&post_type=page</code></p>
<p>This is returning pages and posts.</p>
<p>How do I r... | [
{
"answer_id": 232467,
"author": "fuxia",
"author_id": 73,
"author_profile": "https://wordpress.stackexchange.com/users/73",
"pm_score": 3,
"selected": true,
"text": "<p>You can enforce a post type per callback on <code>pre_get_posts</code>:</p>\n\n<pre><code>is_admin() || add_action( 'p... | 2016/07/17 | [
"https://wordpress.stackexchange.com/questions/232462",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/75134/"
] | I'm trying to return only pages in search results.
This is working:
`/?s=term&post_type=post`
It returns only posts, no pages.
But the opposite is not working:
`/?s=term&post_type=page`
This is returning pages and posts.
How do I return only pages?
**Edit**
Forgot to mention, so I'm trying to allow the ability... | You can enforce a post type per callback on `pre_get_posts`:
```
is_admin() || add_action( 'pre_get_posts', function( \WP_Query $query ) {
$post_type = filter_input( INPUT_GET, 'post_type', FILTER_SANITIZE_STRING );
if ( $post_type && $query->is_main_query() && $query->is_search() )
$query->set( 'pos... |
232,465 | <p>I am trying to write a function to upload and delete images on frontend with dropzonejs uploader, and so far i managed to make everything work.</p>
<p>But the problem is that i need to secure it that the image that is deleting is actually uploaded by the user who is deleting image.</p>
<p>In wordpress admin area i... | [
{
"answer_id": 232467,
"author": "fuxia",
"author_id": 73,
"author_profile": "https://wordpress.stackexchange.com/users/73",
"pm_score": 3,
"selected": true,
"text": "<p>You can enforce a post type per callback on <code>pre_get_posts</code>:</p>\n\n<pre><code>is_admin() || add_action( 'p... | 2016/07/17 | [
"https://wordpress.stackexchange.com/questions/232465",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/21135/"
] | I am trying to write a function to upload and delete images on frontend with dropzonejs uploader, and so far i managed to make everything work.
But the problem is that i need to secure it that the image that is deleting is actually uploaded by the user who is deleting image.
In wordpress admin area in media library w... | You can enforce a post type per callback on `pre_get_posts`:
```
is_admin() || add_action( 'pre_get_posts', function( \WP_Query $query ) {
$post_type = filter_input( INPUT_GET, 'post_type', FILTER_SANITIZE_STRING );
if ( $post_type && $query->is_main_query() && $query->is_search() )
$query->set( 'pos... |
232,471 | <p>In content I can have multiple shortcodes like <code>[book id="1"] [book id="14" page="243"]</code></p>
<p>Is there any help method with which I can search the content for that shortcode and get its parameters? I need to get IDs so I can call WP_Query and append the Custom Post Types titles at the end.</p>
<pre><c... | [
{
"answer_id": 232648,
"author": "Marko",
"author_id": 47357,
"author_profile": "https://wordpress.stackexchange.com/users/47357",
"pm_score": 3,
"selected": true,
"text": "<p>This is working for me</p>\n\n<pre><code> $shortcode = 'book';\n $pattern = get_shortcode_regex();\n\n // if ... | 2016/07/17 | [
"https://wordpress.stackexchange.com/questions/232471",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/47357/"
] | In content I can have multiple shortcodes like `[book id="1"] [book id="14" page="243"]`
Is there any help method with which I can search the content for that shortcode and get its parameters? I need to get IDs so I can call WP\_Query and append the Custom Post Types titles at the end.
```
function filter_books( $con... | This is working for me
```
$shortcode = 'book';
$pattern = get_shortcode_regex();
// if shortcode 'book' exists
if ( preg_match_all( '/'. $pattern .'/s', $post->post_content, $matches )
&& array_key_exists( 2, $matches )
&& in_array( $shortcode, $matches[2] ) ) {
$shortcode_atts = array_keys($matc... |
232,490 | <p>When I click on "older entries" in my home page, it goes to a second link but it shows the same posts. I think I need to modify something in the <code>index.php</code>, this is the full code section that I think I need to modify:</p>
<pre><code><div class="container">
<div class="post_content">
... | [
{
"answer_id": 232922,
"author": "majick",
"author_id": 76440,
"author_profile": "https://wordpress.stackexchange.com/users/76440",
"pm_score": 0,
"selected": false,
"text": "<p>If the posts are being displayed via a static front page (they seem to be?) then you need to use the query par... | 2016/07/18 | [
"https://wordpress.stackexchange.com/questions/232490",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/91761/"
] | When I click on "older entries" in my home page, it goes to a second link but it shows the same posts. I think I need to modify something in the `index.php`, this is the full code section that I think I need to modify:
```
<div class="container">
<div class="post_content">
<div class="home_posts">
... | Why don't you try with default query and use like this
```
if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
else { $paged = 1; }
$args = array(
'post_type' => 'post',
'posts_per_page' => 6,
'paged' => $paged... |
232,498 | <p>I am currently working on <a href="http://www.highereg.com/member-list/starr-mazer" rel="nofollow noreferrer">this website</a> which uses a Wordpress theme designed by one Themeforest author. As can be seen via the link and the following screenshot from the same page, the theme's Portfolio (Custom Post Type) utilise... | [
{
"answer_id": 232499,
"author": "tillinberlin",
"author_id": 26059,
"author_profile": "https://wordpress.stackexchange.com/users/26059",
"pm_score": 0,
"selected": false,
"text": "<p>Short answer: most probably there is.</p>\n\n<p>I would recommend you use a child theme to achieve this.... | 2016/07/18 | [
"https://wordpress.stackexchange.com/questions/232498",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98478/"
] | I am currently working on [this website](http://www.highereg.com/member-list/starr-mazer) which uses a Wordpress theme designed by one Themeforest author. As can be seen via the link and the following screenshot from the same page, the theme's Portfolio (Custom Post Type) utilises 8 columns for textual and any other da... | Why don't you create a [shortcode](https://codex.wordpress.org/Shortcode_API) for this , it's much easier, standard and flexible. |
232,513 | <p>I want to use Pagination using ajax for custom post taxonomy.
Many of codes are tried by me but at the last I was failed. So,how can i use pagination using ajax without plugin?</p>
<p>When i am clicking on load more button then the post will load on the same page.</p>
<p><strong>post name:- project</strong></p>
<... | [
{
"answer_id": 232711,
"author": "jayesh",
"author_id": 98495,
"author_profile": "https://wordpress.stackexchange.com/users/98495",
"pm_score": 4,
"selected": true,
"text": "<p>I had got the ans.</p>\n\n<p>First you have to add following code in your function.php to call ajax in your tem... | 2016/07/18 | [
"https://wordpress.stackexchange.com/questions/232513",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98495/"
] | I want to use Pagination using ajax for custom post taxonomy.
Many of codes are tried by me but at the last I was failed. So,how can i use pagination using ajax without plugin?
When i am clicking on load more button then the post will load on the same page.
**post name:- project**
**taxonomy name:- framework**
**`f... | I had got the ans.
First you have to add following code in your function.php to call ajax in your template\*\*
```
add_action( 'wp_ajax_demo-pagination-load-posts', 'cvf_demo_pagination_load_posts' );
add_action( 'wp_ajax_nopriv_demo-pagination-load-posts', 'cvf_demo_pagination_load_posts' );
function cvf_demo_pag... |
232,527 | <p>I have set up a fresh installation of WordPress 4.5.3 and activated the Multisite feature, following all the instructions required to activate it.</p>
<p>I added a second site, and once it was created I tried clicking on the dashboard for the second site but it directs me to the first site dashboard, everytime!</p>... | [
{
"answer_id": 232571,
"author": "Pat J",
"author_id": 16121,
"author_profile": "https://wordpress.stackexchange.com/users/16121",
"pm_score": 1,
"selected": false,
"text": "<p>Make sure you've set up your rewrite rules in your <code>.htaccess</code> file. The Multisite rules are differe... | 2016/07/18 | [
"https://wordpress.stackexchange.com/questions/232527",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98503/"
] | I have set up a fresh installation of WordPress 4.5.3 and activated the Multisite feature, following all the instructions required to activate it.
I added a second site, and once it was created I tried clicking on the dashboard for the second site but it directs me to the first site dashboard, everytime!
I tried to v... | Make sure you've set up your rewrite rules in your `.htaccess` file. The Multisite rules are different from the default WordPress rules.
If this is an up-to-date version of WordPress, your `.htaccess` rewrite rules should look like this:
Subdirectory
------------
```
RewriteEngine On
RewriteBase /
RewriteRule ^index... |
232,600 | <p>I'm trying to get the <code>current-menu-item-id</code> in any page.
I have used <a href="https://wordpress.stackexchange.com/questions/16243/how-to-get-current-menu-item-title-as-variable">this solution</a>, that brings me very close to the solution.</p>
<p>The problem I have is, that the function below is going t... | [
{
"answer_id": 232581,
"author": "ngearing",
"author_id": 50184,
"author_profile": "https://wordpress.stackexchange.com/users/50184",
"pm_score": 4,
"selected": true,
"text": "<p>Yes!</p>\n\n<ol>\n<li>Go to your Media Library </li>\n<li>Find the Image </li>\n<li>Click Edit </li>\n<li>Lo... | 2016/07/19 | [
"https://wordpress.stackexchange.com/questions/232600",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/97806/"
] | I'm trying to get the `current-menu-item-id` in any page.
I have used [this solution](https://wordpress.stackexchange.com/questions/16243/how-to-get-current-menu-item-title-as-variable), that brings me very close to the solution.
The problem I have is, that the function below is going through all the menus on the page... | Yes!
1. Go to your Media Library
2. Find the Image
3. Click Edit
4. Locate the Permalink under the Title
5. Click Edit
6. Change the Permalink
7. Click Update!
Edit
----
If for some reason you cannot Edit the Images' Permalink... you could:
1. Delete Image
2. Change your Pages' Permalink
3. Re-Upload Image |
232,610 | <p>I have the following code:-</p>
<pre><code><!-- News Archive -->
<div id="news-archive">
<div class="row">
<div class="col-md-12">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'p... | [
{
"answer_id": 232970,
"author": "wpclevel",
"author_id": 92212,
"author_profile": "https://wordpress.stackexchange.com/users/92212",
"pm_score": 3,
"selected": true,
"text": "<p>You can calculate <code>offset</code> via <code>paged</code> and <code>posts_per_page</code>. E.g:</p>\n\n<pr... | 2016/07/19 | [
"https://wordpress.stackexchange.com/questions/232610",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/81966/"
] | I have the following code:-
```
<!-- News Archive -->
<div id="news-archive">
<div class="row">
<div class="col-md-12">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'post',
'orderby' => 'title'... | You can calculate `offset` via `paged` and `posts_per_page`. E.g:
```
$per_page = 6;
$paged = get_query_var('paged') ? : 1;
$offset = (1 === $paged) ? 0 : (($paged - 1) * $per_page) + (($paged - 1) * 2);
$args = array(
'order' => 'ASC',
'paged' => $paged,
'offset' => $offset,
'orderby' => 'ID',
'post_t... |
232,663 | <p>I am trying to post to WordPress using the REST API. The aim is to have a form that accepts The following information:</p>
<ul>
<li>Title</li>
<li>Content</li>
<li>ACF Custom Field 1 (possibly repeater field)</li>
<li>ACF Custom Field 2 (possibly repeater field)</li>
<li>Featured Image</li>
</ul>
<p>I am new to th... | [
{
"answer_id": 232664,
"author": "whakawaehere",
"author_id": 78660,
"author_profile": "https://wordpress.stackexchange.com/users/78660",
"pm_score": -1,
"selected": false,
"text": "<p>I think the simplest solution, without having more details about site A or site B, would be to use a se... | 2016/07/19 | [
"https://wordpress.stackexchange.com/questions/232663",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/64567/"
] | I am trying to post to WordPress using the REST API. The aim is to have a form that accepts The following information:
* Title
* Content
* ACF Custom Field 1 (possibly repeater field)
* ACF Custom Field 2 (possibly repeater field)
* Featured Image
I am new to the WP API and am having some difficulty finding some soli... | To answer your broader question about resources - while there are many articles out there, I would always recommend checking out the official [WordPress API Handbook](https://developer.wordpress.org/rest-api/reference/posts/) first.
You first have to decide which JavaScript library you want to use to make HTTP request... |
232,675 | <p>I am trying to figure out how to add user information and specific meta data to a separate table through PHP. I would prefer to do this when a user posted to the <code>wp_users</code> and <code>wp_usermeta</code> table. I am using the WooCommerce Auction plugin and the Salient theme.</p>
<p>Also if I made a PHP fil... | [
{
"answer_id": 232685,
"author": "stoi2m1",
"author_id": 10907,
"author_profile": "https://wordpress.stackexchange.com/users/10907",
"pm_score": 0,
"selected": false,
"text": "<p><strong>NOTE:</strong> This answer looks irrelevant to the OP's question after further analysis of the added/... | 2016/07/20 | [
"https://wordpress.stackexchange.com/questions/232675",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98590/"
] | I am trying to figure out how to add user information and specific meta data to a separate table through PHP. I would prefer to do this when a user posted to the `wp_users` and `wp_usermeta` table. I am using the WooCommerce Auction plugin and the Salient theme.
Also if I made a PHP file that ran a query to pull the d... | Looks to me you should be seeking a woocommerce purchase completion hook. This would be when you could add that a donation has been made and at what amount, then you could grab any user information, amounted donated and other info you need and save it to your donor table.
use this:
```
add_action('woocommerce_order_s... |
232,692 | <p>I have to make several changes to a website, and I'm willing to setup a copy of the current one on a subdirectory, on the same server.</p>
<p>I.E. if my site is <code>www.example.com</code>, what I'm trying to do is to fully copy it to <code>www.example.com/new/</code>, make all the necessary modifications, then, o... | [
{
"answer_id": 232685,
"author": "stoi2m1",
"author_id": 10907,
"author_profile": "https://wordpress.stackexchange.com/users/10907",
"pm_score": 0,
"selected": false,
"text": "<p><strong>NOTE:</strong> This answer looks irrelevant to the OP's question after further analysis of the added/... | 2016/07/20 | [
"https://wordpress.stackexchange.com/questions/232692",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98169/"
] | I have to make several changes to a website, and I'm willing to setup a copy of the current one on a subdirectory, on the same server.
I.E. if my site is `www.example.com`, what I'm trying to do is to fully copy it to `www.example.com/new/`, make all the necessary modifications, then, once it is done, copy it back to ... | Looks to me you should be seeking a woocommerce purchase completion hook. This would be when you could add that a donation has been made and at what amount, then you could grab any user information, amounted donated and other info you need and save it to your donor table.
use this:
```
add_action('woocommerce_order_s... |
232,752 | <p>I'm trying to write a little script within my <code>footer.php</code> (which I'll later transform into a plugin) that send two form fields to a custom table (<code>wp_newsletter</code>). I'm already sending the form and writing to the table correctly, but I don't know how I can send a success or fail message back to... | [
{
"answer_id": 232760,
"author": "scott",
"author_id": 93587,
"author_profile": "https://wordpress.stackexchange.com/users/93587",
"pm_score": 1,
"selected": false,
"text": "<p>When I realized that PHP is an acronym for \"PHP Hypertext Preprocessor\" -- emphasis on \"preprocessor\" -- I ... | 2016/07/20 | [
"https://wordpress.stackexchange.com/questions/232752",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/60070/"
] | I'm trying to write a little script within my `footer.php` (which I'll later transform into a plugin) that send two form fields to a custom table (`wp_newsletter`). I'm already sending the form and writing to the table correctly, but I don't know how I can send a success or fail message back to the user. My current cod... | It returns either the number of rows inserted or false on error.
Maybe you can get id of inserted recode or false if the insert fails:
**refer link**: <https://developer.wordpress.org/reference/classes/wpdb/insert/#return>
So you can check like below:
```
$result_check = $wpdb->insert( $table, array("name" => $nam... |
232,759 | <p>I'm trying to add an incremental variable to each post that comes up in a series of queries. The purpose is to calculate a weight for each result in order to be able to order everything later.</p>
<p>This is what I've come up with so far, but I'm doing something wrong, as the weights seem to add up globally instead... | [
{
"answer_id": 232760,
"author": "scott",
"author_id": 93587,
"author_profile": "https://wordpress.stackexchange.com/users/93587",
"pm_score": 1,
"selected": false,
"text": "<p>When I realized that PHP is an acronym for \"PHP Hypertext Preprocessor\" -- emphasis on \"preprocessor\" -- I ... | 2016/07/20 | [
"https://wordpress.stackexchange.com/questions/232759",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/70333/"
] | I'm trying to add an incremental variable to each post that comes up in a series of queries. The purpose is to calculate a weight for each result in order to be able to order everything later.
This is what I've come up with so far, but I'm doing something wrong, as the weights seem to add up globally instead of for ea... | It returns either the number of rows inserted or false on error.
Maybe you can get id of inserted recode or false if the insert fails:
**refer link**: <https://developer.wordpress.org/reference/classes/wpdb/insert/#return>
So you can check like below:
```
$result_check = $wpdb->insert( $table, array("name" => $nam... |
232,774 | <p>I'm displaying the current user's info on the front-end, but haven't been able to locate the correct hook for the bio, other than as an "author" hook. Help?</p>
| [
{
"answer_id": 232778,
"author": "jgraup",
"author_id": 84219,
"author_profile": "https://wordpress.stackexchange.com/users/84219",
"pm_score": 2,
"selected": false,
"text": "<p>You probably want to use <a href=\"https://codex.wordpress.org/Function_Reference/wp_get_current_user\" rel=\"... | 2016/07/21 | [
"https://wordpress.stackexchange.com/questions/232774",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/88351/"
] | I'm displaying the current user's info on the front-end, but haven't been able to locate the correct hook for the bio, other than as an "author" hook. Help? | You probably want to use [`wp_get_current_user`](https://codex.wordpress.org/Function_Reference/wp_get_current_user) to find out which user is browsing the site.
```
$current_user = wp_get_current_user();
echo 'User ID: ' . $current_user->ID . '<br />';
```
From there you'll use the `ID` to pull the user's metadata... |
232,796 | <p>Having a few issues getting things to work after changing wordpress from http to https on a windows sever. The web.config file is a bit of a mare to work with and the hosting company seems to think that changing http to https in wordpress settings is the only change necessary. currently I can only get the site to lo... | [
{
"answer_id": 232778,
"author": "jgraup",
"author_id": 84219,
"author_profile": "https://wordpress.stackexchange.com/users/84219",
"pm_score": 2,
"selected": false,
"text": "<p>You probably want to use <a href=\"https://codex.wordpress.org/Function_Reference/wp_get_current_user\" rel=\"... | 2016/07/21 | [
"https://wordpress.stackexchange.com/questions/232796",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98674/"
] | Having a few issues getting things to work after changing wordpress from http to https on a windows sever. The web.config file is a bit of a mare to work with and the hosting company seems to think that changing http to https in wordpress settings is the only change necessary. currently I can only get the site to load ... | You probably want to use [`wp_get_current_user`](https://codex.wordpress.org/Function_Reference/wp_get_current_user) to find out which user is browsing the site.
```
$current_user = wp_get_current_user();
echo 'User ID: ' . $current_user->ID . '<br />';
```
From there you'll use the `ID` to pull the user's metadata... |
232,802 | <p>I just want to remove <strong>Comment's column</strong> in <strong>all post-types</strong> and in a <strong>single function</strong></p>
<p><a href="https://i.stack.imgur.com/xUdLd.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xUdLd.gif" alt="enter image description here"></a></p>
<p><strong>M... | [
{
"answer_id": 232803,
"author": "l2aelba",
"author_id": 6332,
"author_profile": "https://wordpress.stackexchange.com/users/6332",
"pm_score": 3,
"selected": true,
"text": "<p><strong>I got an alternative :</strong></p>\n\n<p><em>This will not just hiding but disabling also</em></p>\n\n<... | 2016/07/21 | [
"https://wordpress.stackexchange.com/questions/232802",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/6332/"
] | I just want to remove **Comment's column** in **all post-types** and in a **single function**
[](https://i.stack.imgur.com/xUdLd.gif)
**My current function , Have to do each post-type like this :**
```
function remove_post_columns($columns) {
un... | **I got an alternative :**
*This will not just hiding but disabling also*
```
function disable_comments() {
$post_types = get_post_types();
foreach ($post_types as $post_type) {
if(post_type_supports($post_type,'comments')) {
remove_post_type_support($post_type,'comments');
rem... |
232,809 | <p>Hello I have code intended to get the most viewed post for last 2 days and it seems like not working or maybe my code is just incorrect. I appreciate any help. Thanks.</p>
<pre><code> $args = array(
'post_type' => 'post',
'meta_key' => 'post_views_count',
'orderby' => 'meta_value_num',
... | [
{
"answer_id": 232987,
"author": "Marc",
"author_id": 71657,
"author_profile": "https://wordpress.stackexchange.com/users/71657",
"pm_score": 0,
"selected": false,
"text": "<p>Try adjusting your <code>$args</code>. You will need to get the date from two days ago and then pass the year, m... | 2016/07/21 | [
"https://wordpress.stackexchange.com/questions/232809",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98686/"
] | Hello I have code intended to get the most viewed post for last 2 days and it seems like not working or maybe my code is just incorrect. I appreciate any help. Thanks.
```
$args = array(
'post_type' => 'post',
'meta_key' => 'post_views_count',
'orderby' => 'meta_value_num',
'date_query' => array(... | I had the same issue. I had searched many times for this issue. but I could not find a solution for this.
>
> get the most viewed post for the last 2 days not to get the posts for the last 2 days
>
>
>
I have a table named "wp\_popularpostssummary".
[.</p>
<p>Please see attached image.
<a href="https://i.stack.imgur.com/... | [
{
"answer_id": 232987,
"author": "Marc",
"author_id": 71657,
"author_profile": "https://wordpress.stackexchange.com/users/71657",
"pm_score": 0,
"selected": false,
"text": "<p>Try adjusting your <code>$args</code>. You will need to get the date from two days ago and then pass the year, m... | 2016/07/21 | [
"https://wordpress.stackexchange.com/questions/232818",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98690/"
] | after migrating my WP site to a different domain and making adjustments, Font Awesome stopped showing icons and shows some weird text instead, for example & # 61505; (I can't copy it as a text, looks like an automatically generated graphics).
Please see attached image.
[;
$meta_query = array( 'relation' => 'AND' );
if($location) {
$meta_query[] = arra... | [
{
"answer_id": 232828,
"author": "FaCE",
"author_id": 96768,
"author_profile": "https://wordpress.stackexchange.com/users/96768",
"pm_score": 2,
"selected": false,
"text": "<p>Have you <code>var_dump</code>ed <code>$location</code>?</p>\n\n<p><code>WP_Query</code>'s <code>meta_query</cod... | 2016/07/21 | [
"https://wordpress.stackexchange.com/questions/232826",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/36773/"
] | I have a form on a page that search property with a location field and I used the following meta query to process the search;
```
$location = preg_replace('/^-|-$|[^-a-zA-Z0-9]/', '', $_GET['location']);
$meta_query = array( 'relation' => 'AND' );
if($location) {
$meta_query[] = array(
'r... | Have you `var_dump`ed `$location`?
`WP_Query`'s `meta_query` uses the class `WP_Meta_Query`, which automatically appends and prepends '%' to any *string* passed to it:
```
// From wp-includes/class-wp-meta-query.php:610
switch ( $meta_compare ) {
// ...
case 'LIKE' :
case 'NOT LIK... |
232,873 | <p>I created a page template to list all products of a specific product line.
Now I want to list all posts from this custom post type (products) based on the taxonomy described in the shortcode for each page.</p>
<p>Example:</p>
<p>Page "List of all Prime products"</p>
<p>[products line="prime"]</p>
<p>I tried this... | [
{
"answer_id": 232879,
"author": "Howdy_McGee",
"author_id": 7355,
"author_profile": "https://wordpress.stackexchange.com/users/7355",
"pm_score": 4,
"selected": true,
"text": "<p>First off, it's always good to register shortcode during <code>init</code> versus just in your general <code... | 2016/07/21 | [
"https://wordpress.stackexchange.com/questions/232873",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/98722/"
] | I created a page template to list all products of a specific product line.
Now I want to list all posts from this custom post type (products) based on the taxonomy described in the shortcode for each page.
Example:
Page "List of all Prime products"
[products line="prime"]
I tried this code:
```
function shortcode_... | First off, it's always good to register shortcode during `init` versus just in your general `functions.php` file. At the very least `add_shortcode()` should be in `init`. Anyway, let's begin!
Whenever you use [`add_shortcode()`](https://codex.wordpress.org/Function_Reference/add_shortcode) the first parameter is going... |