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 |
|---|---|---|---|---|---|---|
202,121 | <p>I need to import catalog data from external server.
The data is arranged in categories and then items.</p>
<p>the API requires the following calls:
1. Get categories
2. Get category items
3. get item data</p>
<p>this task works once a day by using a cron job.
the catalog contains about 5000 items.</p>
<p>items im... | [
{
"answer_id": 202123,
"author": "Mark Kaplun",
"author_id": 23970,
"author_profile": "https://wordpress.stackexchange.com/users/23970",
"pm_score": 0,
"selected": false,
"text": "<p><code>set_time_limit(0)</code> will disable the time limit check and should solve the problem if that is ... | 2015/09/09 | [
"https://wordpress.stackexchange.com/questions/202121",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/395/"
] | I need to import catalog data from external server.
The data is arranged in categories and then items.
the API requires the following calls:
1. Get categories
2. Get category items
3. get item data
this task works once a day by using a cron job.
the catalog contains about 5000 items.
items import is encapsulated int... | For avoid timeout best option is wp-cli.
Wp-cli is wordpress command line interface. you can export/import data using wp-cli. |
202,124 | <p>I have a bash script that installs and activates a theme like this: </p>
<p>wp theme install <a href="https://bitbucket.org/organization/theme/get/master.zip" rel="nofollow">https://bitbucket.org/organization/theme/get/master.zip</a> --activate</p>
<p>The problem is that it only works with public repositories, rat... | [
{
"answer_id": 202130,
"author": "chap",
"author_id": 48204,
"author_profile": "https://wordpress.stackexchange.com/users/48204",
"pm_score": 3,
"selected": true,
"text": "<p>I actually figured out a way to do this. First you use wget like this: </p>\n\n<pre><code>wget --user username --... | 2015/09/09 | [
"https://wordpress.stackexchange.com/questions/202124",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/48204/"
] | I have a bash script that installs and activates a theme like this:
wp theme install <https://bitbucket.org/organization/theme/get/master.zip> --activate
The problem is that it only works with public repositories, rather than private ones. If I make the repository private I get this error:
```
Unpacking the packag... | I actually figured out a way to do this. First you use wget like this:
```
wget --user username --ask-password -O path/to/output.zip https://bitbucket.org/path/to/file.zip
```
the -O flag specifies output and output.zip is where you want it to download to.
Then you can run:
```
wp theme install path/to/output.zip... |
202,127 | <pre><code><?php
/**
* The template for displaying comments.
*
* The area of the page that contains both current comments
* and the comment form.
*
* @package Tesseract
*/
/*
* If the current post is protected by a password and
* the visitor has not yet entered the password we will
* return early without ... | [
{
"answer_id": 202128,
"author": "Robert hue",
"author_id": 22461,
"author_profile": "https://wordpress.stackexchange.com/users/22461",
"pm_score": 2,
"selected": false,
"text": "<p>You needed to move <code><?php comment_form(); ?></code> at the top, just above comment header title... | 2015/09/09 | [
"https://wordpress.stackexchange.com/questions/202127",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80103/"
] | ```
<?php
/**
* The template for displaying comments.
*
* The area of the page that contains both current comments
* and the comment form.
*
* @package Tesseract
*/
/*
* If the current post is protected by a password and
* the visitor has not yet entered the password we will
* return early without loading th... | You needed to move `<?php comment_form(); ?>` at the top, just above comment header title.
Here is the modified code.
```
<?php
/**
* The template for displaying comments.
*
* The area of the page that contains both current comments
* and the comment form.
*
* @package Tesseract
*/
/*
* If the current post i... |
202,134 | <p>I have a custom post type called <code>dramas</code></p>
<pre><code>/******* DRAMAS BEGIN *****************************************/
register_post_type('dramas', array(
'label' => 'Dramas',
'show_ui' => true,
'supports' => array('title', 'thumbnail', 'description'),
'labels' => array (
... | [
{
"answer_id": 202142,
"author": "Riffaz Starr",
"author_id": 43764,
"author_profile": "https://wordpress.stackexchange.com/users/43764",
"pm_score": 3,
"selected": true,
"text": "<p>You custom post type is <strong>NO</strong>T public.</p>\n\n<p>Add following lines to your <strong>regist... | 2015/09/09 | [
"https://wordpress.stackexchange.com/questions/202134",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/69828/"
] | I have a custom post type called `dramas`
```
/******* DRAMAS BEGIN *****************************************/
register_post_type('dramas', array(
'label' => 'Dramas',
'show_ui' => true,
'supports' => array('title', 'thumbnail', 'description'),
'labels' => array (
'name' => 'Dramas',
's... | You custom post type is **NO**T public.
Add following lines to your **register\_post\_type** `array`
```
'public' => true,
'publicly_queryable' => true,
``` |
202,143 | <p>I have to do something but I just can't come up with a way to do it.<br><br>
On one hand I have created pages who are companies. So every page is a company-page.<br>
On the other hand I have created users who have a custom field added to their profile that holds the name of the company they work at.</p>
<p>No this ... | [
{
"answer_id": 202152,
"author": "Arjan Kuiken",
"author_id": 76871,
"author_profile": "https://wordpress.stackexchange.com/users/76871",
"pm_score": 0,
"selected": false,
"text": "<p>this can be best solved by adding constraints in your database schemes. The best way to achieve this is ... | 2015/09/09 | [
"https://wordpress.stackexchange.com/questions/202143",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/52240/"
] | I have to do something but I just can't come up with a way to do it.
On one hand I have created pages who are companies. So every page is a company-page.
On the other hand I have created users who have a custom field added to their profile that holds the name of the company they work at.
No this is merely a conn... | It gives an array with objects. So `in_array()` won't find anything, you have to convert it before. After you get the results from wbdb:
```
$employees_array = array();
foreach($employees as $employee) {
$employees_array[] = $employee->meta_value;
}
if(in_array($company, $employees_array)) {
...
}
``` |
202,159 | <p>I created a custom taxonomy using following code.</p>
<pre><code>add_action( 'init', 'schedule_day_tax_func' );
function schedule_day_tax_func() {
register_taxonomy(
'schedule_day_taxonomy',
'schedule',
array(
'hierarchical' => true,
'label' => 'Day',
... | [
{
"answer_id": 202189,
"author": "birgire",
"author_id": 26350,
"author_profile": "https://wordpress.stackexchange.com/users/26350",
"pm_score": 3,
"selected": true,
"text": "<h2>Method #1 - Modifying the query arguments</h2>\n\n<p>If we want to modify the <em>term order</em> for the <co... | 2015/09/09 | [
"https://wordpress.stackexchange.com/questions/202159",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/69828/"
] | I created a custom taxonomy using following code.
```
add_action( 'init', 'schedule_day_tax_func' );
function schedule_day_tax_func() {
register_taxonomy(
'schedule_day_taxonomy',
'schedule',
array(
'hierarchical' => true,
'label' => 'Day',
'query_var' =>... | Method #1 - Modifying the query arguments
-----------------------------------------
If we want to modify the *term order* for the `schedule_day_taxonomy` term checklist, on the single `schedule` cpt edit screen, then we can use the following setup:
```
add_action( 'load-post.php', function()
{
add_filter( 'wp_ter... |
202,173 | <p>I am trying to replace the categories metabox with what looks and works like the tags metabox because there's too much hierarchy and scrolling to check the appropriate categories and sub-categories isn't an option. So in my case tags'-like metabox is better.</p>
<p>This is how I am doing it:</p>
<pre><code>/*
* N... | [
{
"answer_id": 202452,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 2,
"selected": false,
"text": "<blockquote>\n <p>How do the 'tag' and 'category' (default) taxonomies do 'save_post' action?</p>\n</blockquote>\n\n... | 2015/09/09 | [
"https://wordpress.stackexchange.com/questions/202173",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/10691/"
] | I am trying to replace the categories metabox with what looks and works like the tags metabox because there's too much hierarchy and scrolling to check the appropriate categories and sub-categories isn't an option. So in my case tags'-like metabox is better.
This is how I am doing it:
```
/*
* Non-hierarchal metabox... | It's informative to check out the `/wp-admin/post.php` file, that contains the `edit_post()` function that calls `wp_update_post()`, which is a `wp_insert_post()` wrapper.
Here's a skeleton for saving the assigned category terms:
```
/**
* Saving assigned category terms (skeleton)
*/
add_action( 'admin_action_editp... |
202,188 | <p>I have created custom post type <code>gallery</code>. </p>
<p>How change the <code>previous post</code> and <code>next post</code> link to point to the current Authors posts only?</p>
<p>The Previous and Next Post link should not display if there are no more posts</p>
<p><a href="https://i.stack.imgur.com/Z4tQ2.... | [
{
"answer_id": 202292,
"author": "Shahrukh Khan",
"author_id": 67596,
"author_profile": "https://wordpress.stackexchange.com/users/67596",
"pm_score": -1,
"selected": true,
"text": "<p>To limit post navigation to the same author and category, locate the link-template.php file in the /wp-... | 2015/09/09 | [
"https://wordpress.stackexchange.com/questions/202188",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/67596/"
] | I have created custom post type `gallery`.
How change the `previous post` and `next post` link to point to the current Authors posts only?
The Previous and Next Post link should not display if there are no more posts
[](https://i.stack.imgur.com/Z4... | To limit post navigation to the same author and category, locate the link-template.php file in the /wp-includes/ folder, and edit using your favorite text editor (Notepad++ for me). In this file you will alter four functions. Locate the following lines in the link-template.php file:
```
function previous_post_link($fo... |
202,200 | <p>I have some dynamic templates where I have to customize the canonical links. </p>
<p>According to Yoast documentation the hook to use is <code>wpseo_canonical</code></p>
<p>I have two functions pointing to different pages IDs:</p>
<pre><code>add_filter('wpseo_canonical', 'listpagecanonical');
function listpagecan... | [
{
"answer_id": 202202,
"author": "Max",
"author_id": 78380,
"author_profile": "https://wordpress.stackexchange.com/users/78380",
"pm_score": 3,
"selected": true,
"text": "<p>Filters should be returned even if your condition fails. You are currently just returning the output when your con... | 2015/09/09 | [
"https://wordpress.stackexchange.com/questions/202200",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15574/"
] | I have some dynamic templates where I have to customize the canonical links.
According to Yoast documentation the hook to use is `wpseo_canonical`
I have two functions pointing to different pages IDs:
```
add_filter('wpseo_canonical', 'listpagecanonical');
function listpagecanonical($string) {
if (is_page(1)){
... | Filters should be returned even if your condition fails. You are currently just returning the output when your condition is met, not when it fails.
`return $string;` at the end of each function should solve your issue.
EXAMPLE
-------
```
add_filter('wpseo_canonical', 'listpagecanonical');
function listpagecanonical... |
202,220 | <p>I have tried using <code>sanitize_text_field()</code> and <code>esc_attr()</code> to filter checkbox data when saving their values to the database, but it is causing the data not being saved.</p>
<p>What is causing it and what's the correct way to filter input <code>checkbox</code> and <code>radio</code>?</p>
| [
{
"answer_id": 202222,
"author": "bueltge",
"author_id": 170,
"author_profile": "https://wordpress.stackexchange.com/users/170",
"pm_score": 1,
"selected": false,
"text": "<p>I mean that the value of checkbox or radio is often a integer value. If is a integer value, then set it to a inte... | 2015/09/09 | [
"https://wordpress.stackexchange.com/questions/202220",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/32989/"
] | I have tried using `sanitize_text_field()` and `esc_attr()` to filter checkbox data when saving their values to the database, but it is causing the data not being saved.
What is causing it and what's the correct way to filter input `checkbox` and `radio`? | I would use the filter\_var() function. It has some predefined filters that you can use depending on what kind of data you are expecting such as string, number, etc.
So to sanitize for a number:
```
$sanitizedNum = filter_var($yourVar, FILTER_SANITIZE_NUMBER_INT);
```
For a string you would just change "\_NUM\_INT"... |
202,252 | <p>I'd like to display the post author's name and avatar on posts sidebar but I can't find any info on it.</p>
<p>Is there a shortcode or piece of code to do this ? </p>
<p>Thanks for your help</p>
| [
{
"answer_id": 202255,
"author": "Tech9logy Creators",
"author_id": 75410,
"author_profile": "https://wordpress.stackexchange.com/users/75410",
"pm_score": 0,
"selected": false,
"text": "<p>if you are using it in <a href=\"http://codex.wordpress.org/The_Loop\" rel=\"nofollow\">Loop</a> t... | 2015/09/10 | [
"https://wordpress.stackexchange.com/questions/202252",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/68671/"
] | I'd like to display the post author's name and avatar on posts sidebar but I can't find any info on it.
Is there a shortcode or piece of code to do this ?
Thanks for your help | Display author's avatar and name in single page sidebar. Add this code in sidebar.php or single.php
```
if ( is_singular( 'post' ) ) {
echo get_avatar( get_the_author_meta( 'user_email' ), 75 );
echo get_the_author_meta( 'display_name' );
}
```
Here 75 number is the avatar size.
I hope it will help you. |
202,260 | <p>I am trying to add a function to my child theme to append the currently logged user as a parameter. For example, when the user test1 logs in and clicks on the following page:</p>
<pre><code>http://www.example.com/my-wishlist
</code></pre>
<p>I want her to be redirected automatically to </p>
<pre><code>http://www.... | [
{
"answer_id": 202263,
"author": "jzatt",
"author_id": 22620,
"author_profile": "https://wordpress.stackexchange.com/users/22620",
"pm_score": 0,
"selected": false,
"text": "<p>You are getting the redirect loop because your script isn't checking if the user already is redirected.</p>\n\n... | 2015/09/10 | [
"https://wordpress.stackexchange.com/questions/202260",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80171/"
] | I am trying to add a function to my child theme to append the currently logged user as a parameter. For example, when the user test1 logs in and clicks on the following page:
```
http://www.example.com/my-wishlist
```
I want her to be redirected automatically to
```
http://www.example.com/my-wishlist/?user=test1
... | Use [add\_query\_arg](https://developer.wordpress.org/reference/functions/add_query_arg/) to make sure the url is created the right way. How is the wishlist link outputted? Trough wp\_nav\_menu? I would add it to the link on creation, so you don't have to use wp\_redirect. |
202,323 | <p>I am on Archive Page of a custom post type <code>gallery</code>.</p>
<p>I have introduced custom permalink variable - <code>author_id</code>.</p>
<p>Lets say i get the permalink variable in <code>$perm_author_id</code>. I want to compare <code>$perm_author_id</code> and <code>get_the_author_meta(ID)</code> and the... | [
{
"answer_id": 202333,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 0,
"selected": false,
"text": "<p>What you want to do is commonly known as modifying the main query. There are a lot of faulty advice out there on to... | 2015/09/10 | [
"https://wordpress.stackexchange.com/questions/202323",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/67596/"
] | I am on Archive Page of a custom post type `gallery`.
I have introduced custom permalink variable - `author_id`.
Lets say i get the permalink variable in `$perm_author_id`. I want to compare `$perm_author_id` and `get_the_author_meta(ID)` and then display the posts if they are equal.
How can I limit posts displayed ... | ```
function comment_author_id($query) {
$author_id = get_query_var( 'hotel_name' );
if ($author_id) {
$query->set('author', $author_id);
}
}
add_action( 'pre_get_posts', 'comment_author_id' );
``` |
202,325 | <p>I want to know how I can change the structure of the permalink to my desired one before saving or publishing my post in Wordpress?<br/>
For instance, when I add the title like <code>the wordpress blog</code> in my post I get the permalink structure similar to the below:<br/></p>
<pre><code>http://localhost/2015/09/... | [
{
"answer_id": 202330,
"author": "Cedon",
"author_id": 80069,
"author_profile": "https://wordpress.stackexchange.com/users/80069",
"pm_score": 0,
"selected": false,
"text": "<p>Underneath the Title field is the slug field. Normally WordPress will automatically create a slug base on what ... | 2015/09/10 | [
"https://wordpress.stackexchange.com/questions/202325",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/75180/"
] | I want to know how I can change the structure of the permalink to my desired one before saving or publishing my post in Wordpress?
For instance, when I add the title like `the wordpress blog` in my post I get the permalink structure similar to the below:
```
http://localhost/2015/09/10/the-wordpress-blog/
```
I... | Finally, I found my answer on my own.
```
//add our action
add_action( 'save_post', 'my_save_post', 11, 2 );
function my_save_post($post_id, $post){
//if it is just a revision don't worry about it
if (wp_is_post_revision($post_id))
return false;
//if the post is an auto-draft we don't want to do anyt... |
202,342 | <p>I am working on setting up the customizer for my theme. I have all of the sections and controls I need, but now I am trying to make some of them only show on certain pages.</p>
<p>My first stop is the sections that relate only to the home page. I read <a href="https://codex.wordpress.org/Class_Reference/WP_Customi... | [
{
"answer_id": 202355,
"author": "StephenRios",
"author_id": 80200,
"author_profile": "https://wordpress.stackexchange.com/users/80200",
"pm_score": 3,
"selected": true,
"text": "<p>The problem was I had multiple loops that each had different queries on the front page. After making sure... | 2015/09/10 | [
"https://wordpress.stackexchange.com/questions/202342",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80200/"
] | I am working on setting up the customizer for my theme. I have all of the sections and controls I need, but now I am trying to make some of them only show on certain pages.
My first stop is the sections that relate only to the home page. I read [here](https://codex.wordpress.org/Class_Reference/WP_Customize_Manager/ad... | The problem was I had multiple loops that each had different queries on the front page. After making sure to reset them each time, this problem resolved itself.
For instance, my new query and loop looks like this:
```
query_posts( array(
'category_name'=>"Cloud, Customer Engagement, Developers, Executive Thought ... |
202,362 | <p>I can already unset (remove specifics from normal posts) in the json returned from the WordPress API. I actually use the following below from this example: <a href="https://css-tricks.com/using-the-wp-api-to-fetch-posts/" rel="nofollow">https://css-tricks.com/using-the-wp-api-to-fetch-posts/</a></p>
<p>What I am h... | [
{
"answer_id": 206790,
"author": "brianlmerritt",
"author_id": 78419,
"author_profile": "https://wordpress.stackexchange.com/users/78419",
"pm_score": 0,
"selected": false,
"text": "<p>Have a look at the wp-api code for pages (which are custom post types).</p>\n\n<p>You can modify the co... | 2015/09/10 | [
"https://wordpress.stackexchange.com/questions/202362",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/57278/"
] | I can already unset (remove specifics from normal posts) in the json returned from the WordPress API. I actually use the following below from this example: <https://css-tricks.com/using-the-wp-api-to-fetch-posts/>
What I am having trouble with and can't figure out, is how to change this so it unsets data from a **Cust... | If possible, only the examples shown in internet is:
```
function qod_remove_extra_data($data, $post, $context) {
// We only want to modify the 'view' context, for reading posts
if ($context !== 'view' || is_wp_error($data)) {
return $data;
}
// Here, we unset any data we do not want to see ... |
202,372 | <p>i want to add a page with html data to show form and get input from user,store it to database and after successful query show next page with massage that the data is inserted successfully.</p>
| [
{
"answer_id": 206790,
"author": "brianlmerritt",
"author_id": 78419,
"author_profile": "https://wordpress.stackexchange.com/users/78419",
"pm_score": 0,
"selected": false,
"text": "<p>Have a look at the wp-api code for pages (which are custom post types).</p>\n\n<p>You can modify the co... | 2015/09/11 | [
"https://wordpress.stackexchange.com/questions/202372",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80223/"
] | i want to add a page with html data to show form and get input from user,store it to database and after successful query show next page with massage that the data is inserted successfully. | If possible, only the examples shown in internet is:
```
function qod_remove_extra_data($data, $post, $context) {
// We only want to modify the 'view' context, for reading posts
if ($context !== 'view' || is_wp_error($data)) {
return $data;
}
// Here, we unset any data we do not want to see ... |
202,408 | <p>I've a theme which loads 'Open Sans' from Google Fonts. Our site is using SSL & we're using a <code>$protocol://</code> to render the font URL</p>
<p>However, I noticed that, some plugin/(s) probably adding 3 different fonts from Google Fonts, & they're being loaded using <code>http://</code> & that thr... | [
{
"answer_id": 202415,
"author": "phoenixlaef",
"author_id": 37261,
"author_profile": "https://wordpress.stackexchange.com/users/37261",
"pm_score": 1,
"selected": false,
"text": "<p>I wanted to make a comment to mention this but I don't have enough rep yet to do so. I had a problem simi... | 2015/09/11 | [
"https://wordpress.stackexchange.com/questions/202408",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/15946/"
] | I've a theme which loads 'Open Sans' from Google Fonts. Our site is using SSL & we're using a `$protocol://` to render the font URL
However, I noticed that, some plugin/(s) probably adding 3 different fonts from Google Fonts, & they're being loaded using `http://` & that throws error such as:
`Blocked loading mixed a... | If the fonts are loaded from a plugin, a hook will have to be used to insert them, you can disable the hook, but you'll need to know where it's coming from. Mostly because you'll need the handle of the script.
There are quite a few different ways it could be done so I'll try to give an example of one way it may be don... |
202,418 | <p>How can i limit comments displayed on the page - <code>reviews</code> by <code>author_id</code>. </p>
<p>Lets say that the <code>author_id</code> to limit to is in variable <code>$author_id_to_limit</code>.</p>
<p>Please tell me how to hook the function to do so.</p>
<p>I would even like to know how to edit the n... | [
{
"answer_id": 202420,
"author": "jas",
"author_id": 80247,
"author_profile": "https://wordpress.stackexchange.com/users/80247",
"pm_score": 2,
"selected": false,
"text": "<p>Hi Just need to make your function to get comments and then use your function output at required places.</p>\n\n<... | 2015/09/11 | [
"https://wordpress.stackexchange.com/questions/202418",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/67596/"
] | How can i limit comments displayed on the page - `reviews` by `author_id`.
Lets say that the `author_id` to limit to is in variable `$author_id_to_limit`.
Please tell me how to hook the function to do so.
I would even like to know how to edit the no of post with this cuurent query. | The `pre_get_comments` hook
---------------------------
Note that the single post's comments are fetched with `get_comments()`, within the `comment_template()` function.
The `get_comments()` function is just a `WP_Comment_Query` object wrapper, so we can restrict the comment query with the `pre_get_comments` hook.
E... |
202,432 | <p>I know I'm doing something that's been done 1000's of times before in WordPress, but struggling to get the terms to find it on the Interwebs.</p>
<p>I've got a custom category template page and have a while loop that shows the first 5 results (of which there are more than 5).</p>
<p>How do I output something withi... | [
{
"answer_id": 202438,
"author": "webmaven",
"author_id": 80260,
"author_profile": "https://wordpress.stackexchange.com/users/80260",
"pm_score": -1,
"selected": false,
"text": "<p>Ok so, This following is how you can have custom wp query with pagination, I also suggest you install this ... | 2015/09/11 | [
"https://wordpress.stackexchange.com/questions/202432",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/10692/"
] | I know I'm doing something that's been done 1000's of times before in WordPress, but struggling to get the terms to find it on the Interwebs.
I've got a custom category template page and have a while loop that shows the first 5 results (of which there are more than 5).
How do I output something within my while that s... | it's been a long time, I had exact the same task and here is the solution
```
$from = ($query->query_vars['posts_per_page'] * $paged) - ($query->query_vars['posts_per_page'] - 1);
if(($query->query_vars['posts_per_page'] * $paged) <= ($query->found_posts)){
$to = ($query->query_vars['posts_per_page'] * $paged);
}els... |
202,457 | <p>I have modified the comment query arguments in <code>comment-template.php</code> from </p>
<pre><code>$author_id = get_query_var( 'author_id', 1 );
$comment_args = array(
'order' => 'ASC',
'orderby' => 'comment_date_gmt',
'status' => 'approve',
... | [
{
"answer_id": 202464,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 0,
"selected": false,
"text": "<p><code>get_comments_number()</code> does not rely on any comment query, it simply reports the number of comments sto... | 2015/09/11 | [
"https://wordpress.stackexchange.com/questions/202457",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/67596/"
] | I have modified the comment query arguments in `comment-template.php` from
```
$author_id = get_query_var( 'author_id', 1 );
$comment_args = array(
'order' => 'ASC',
'orderby' => 'comment_date_gmt',
'status' => 'approve',
);
$comments = get_commen... | >
> ### Refrain from editing core files
>
>
> WordPress was developed with extensibility in mind, and provides many ways to change the appearance and functionality of an installation without altering the WordPress software itself (mostly using [Hooks](https://codex.wordpress.org/Plugin_API#Hooks.2C_Actions_and_Filte... |
202,463 | <p>Among WordPress' <a href="https://codex.wordpress.org/Roles_and_Capabilities" rel="noreferrer">capabilities</a> are <code>unfiltered_html</code> and <code>unfiltered_upload</code>, however I have yet to find any documentation about what specifically they allow or prevent in their filtering. </p>
<p>The only mention... | [
{
"answer_id": 202465,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 3,
"selected": false,
"text": "<p>It is hard to come up with <em>precise</em> answer since capabilities are often used more broadly than they imply. ... | 2015/09/11 | [
"https://wordpress.stackexchange.com/questions/202463",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/26666/"
] | Among WordPress' [capabilities](https://codex.wordpress.org/Roles_and_Capabilities) are `unfiltered_html` and `unfiltered_upload`, however I have yet to find any documentation about what specifically they allow or prevent in their filtering.
The only mention I've found on WordPress' site about `unfiltered_html` is:
... | It is hard to come up with *precise* answer since capabilities are often used more broadly than they imply. For example check for `manage_options` is usually synonym to check for admin user and can come up in contexts that don't actually have much to do with *options*.
*Usually* it will be a difference between subject... |
202,487 | <p>I have a simple table layout as per below:</p>
<pre><code><table>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
<td>6</td>
</tr>
&... | [
{
"answer_id": 202495,
"author": "Tom Berghuis",
"author_id": 63473,
"author_profile": "https://wordpress.stackexchange.com/users/63473",
"pm_score": -1,
"selected": false,
"text": "<pre><code>table:nth-child(1),\ntable tr:nth-child(1) {\n font-weight: bold;\n}\n</code></pre>\n"
},
... | 2015/09/12 | [
"https://wordpress.stackexchange.com/questions/202487",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/62598/"
] | I have a simple table layout as per below:
```
<table>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
<td>6</td>
</tr>
</table>
```
And the following CSS:
```
table td:nth-child(1),
table tr:nth-child(1) {
font-weight: bold;
}
```
The first ... | After much frustration I realised that the issue is the fact that you need ultimately to specify what you do with the **cell** in the nth row, hence the correct code is:
```
table td:nth-child(1),
table tr:nth-child(1) td {
font-weight: bold;
}
```
Putting this up as the answer as there are a lot of sources that u... |
202,489 | <p>In a website I am working on ,there are 50 categories + sub categories, each has a a <strong>very long</strong> description text, then in an archive page I display all the titles of the categories + their description ,but it makes more sense to show the title of each category + a few words of each description (exce... | [
{
"answer_id": 202491,
"author": "cybmeta",
"author_id": 37428,
"author_profile": "https://wordpress.stackexchange.com/users/37428",
"pm_score": 3,
"selected": true,
"text": "<p>I've been looking for a filter for <code>category_description()</code> and I have not found any. You could use... | 2015/09/12 | [
"https://wordpress.stackexchange.com/questions/202489",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/51370/"
] | In a website I am working on ,there are 50 categories + sub categories, each has a a **very long** description text, then in an archive page I display all the titles of the categories + their description ,but it makes more sense to show the title of each category + a few words of each description (excerpt?) and a "read... | I've been looking for a filter for `category_description()` and I have not found any. You could use `wp_trim_words()` with `category_description()` to get the desired result. For example:
```
$cat_ID = 4;
// wp_trim_words( $text, $num_words = 55, $more = null );
echo wp_trim_words( category_description( $cat_ID ), 55... |
202,496 | <p>I run a small site based on wp with user generated content. Users often submit youtube links. And then wordpress automatically converts these links to videos which is <strong>unwanted in our case</strong>. I need to override this automatic behavior so that the submitted youtube links remains in <code>plain text urls... | [
{
"answer_id": 202497,
"author": "jas",
"author_id": 80247,
"author_profile": "https://wordpress.stackexchange.com/users/80247",
"pm_score": 3,
"selected": true,
"text": "<p>disable the oembed like below in functions.php :</p>\n\n<pre><code>remove_filter( 'the_content', array( $GLOBALS['... | 2015/09/12 | [
"https://wordpress.stackexchange.com/questions/202496",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/25508/"
] | I run a small site based on wp with user generated content. Users often submit youtube links. And then wordpress automatically converts these links to videos which is **unwanted in our case**. I need to override this automatic behavior so that the submitted youtube links remains in `plain text urls` ?
I found out that... | disable the oembed like below in functions.php :
```
remove_filter( 'the_content', array( $GLOBALS['wp_embed'], 'autoembed' ), 8 );
```
Thanks! |
202,500 | <p>I'm trying to output the values of two custom fields created by ACF plugin in a custom post type. I actually need this to be displayed in a popup window. wordpress popup plugins don't support php code, only shortcodes can be called from the content editor. So I'm trying to create a shortcode to be used in the editor... | [
{
"answer_id": 270084,
"author": "BigDropGR",
"author_id": 73164,
"author_profile": "https://wordpress.stackexchange.com/users/73164",
"pm_score": 0,
"selected": false,
"text": "<p>Just in case anyone will search for this in the future...</p>\n\n<p>The proper way to output php value thro... | 2015/09/12 | [
"https://wordpress.stackexchange.com/questions/202500",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/73173/"
] | I'm trying to output the values of two custom fields created by ACF plugin in a custom post type. I actually need this to be displayed in a popup window. wordpress popup plugins don't support php code, only shortcodes can be called from the content editor. So I'm trying to create a shortcode to be used in the editor of... | We've built shortcodes in the past using concatenating variables.
To paraphrase the link above, you should output your PHP as such.
```
$output = '<p>';
$output .= '<strong>' . $content . '</strong>';
$output .= '</p>';
return $output;
```
Note, see the `.=` variable concatenation. |
202,502 | <p>I have tried several options like setting <code>'container' => false</code> and registering the <strong>theme_location</strong> and searching on forums but I am unable to get rid of the "div" coming with the wp_nav_menu
in my page:</p>
<pre><code><?php get_nav_menu();?>
function get_nav_menu() {
$navM... | [
{
"answer_id": 202503,
"author": "MD MUSA",
"author_id": 65945,
"author_profile": "https://wordpress.stackexchange.com/users/65945",
"pm_score": 2,
"selected": false,
"text": "<p>FYI :<code>container => ''</code> is a string operation and it's default set by <code>div</code> you can't... | 2015/09/12 | [
"https://wordpress.stackexchange.com/questions/202502",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/74229/"
] | I have tried several options like setting `'container' => false` and registering the **theme\_location** and searching on forums but I am unable to get rid of the "div" coming with the wp\_nav\_menu
in my page:
```
<?php get_nav_menu();?>
function get_nav_menu() {
$navMenuDefaults = array(
'theme_location' =... | FYI :`container => ''` is a string operation and it's default set by `div` you can't use `true or false like bool expression`.
Just change the `container => 'ul'` then i hope you will get what you want to see.
for more details please read this : <https://developer.wordpress.org/reference/functions/wp_nav_menu/>
Thank... |
202,513 | <p>I'm using the <a href="http://civicrm.org" rel="nofollow">CiviCRM</a> plugin for WordPress, and in the plugin's main file, <code>civicrm.php</code>, it calls <code>add_action()</code> to add a function to <code>wp_head()</code> in order to merge CiviCRM's header with my theme's header:</p>
<pre><code>add_action( 'w... | [
{
"answer_id": 202535,
"author": "MD MUSA",
"author_id": 65945,
"author_profile": "https://wordpress.stackexchange.com/users/65945",
"pm_score": 1,
"selected": false,
"text": "<p>Can we think litter bit different way:</p>\n\n<pre><code>add_action('wp_head','new_wp_head');\nfunction new_w... | 2015/09/12 | [
"https://wordpress.stackexchange.com/questions/202513",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80285/"
] | I'm using the [CiviCRM](http://civicrm.org) plugin for WordPress, and in the plugin's main file, `civicrm.php`, it calls `add_action()` to add a function to `wp_head()` in order to merge CiviCRM's header with my theme's header:
```
add_action( 'wp_head', array( $this, 'wp_head' ) );
```
The actual function within ci... | I figured out the issue:
When CiviCRM was applying the template in `civicrm.basepage.php`, `$page_template` was coming back as `page.php`, but my base template was actually named `base.php`.
I added the following code in my theme's initialization and it resolved the issue:
```
add_filter( 'civicrm_basepage_template'... |
202,523 | <p>I've got a shortcode that's got HTML in an $output field that's lovely. I just want to add one paragraph to it at the bottom that's conditional on this statement:</p>
<pre><code><?php if ( get_post_meta( get_the_ID(), 'campus', true ) ) : ?>
</code></pre>
<p>I can't quite figure out how to format a statemen... | [
{
"answer_id": 202544,
"author": "Peter Rigby",
"author_id": 70894,
"author_profile": "https://wordpress.stackexchange.com/users/70894",
"pm_score": 2,
"selected": true,
"text": "<p>If I understand you right you just want to use a '?' type of if statement:</p>\n\n<pre><code>$output = '&l... | 2015/09/12 | [
"https://wordpress.stackexchange.com/questions/202523",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/79967/"
] | I've got a shortcode that's got HTML in an $output field that's lovely. I just want to add one paragraph to it at the bottom that's conditional on this statement:
```
<?php if ( get_post_meta( get_the_ID(), 'campus', true ) ) : ?>
```
I can't quite figure out how to format a statement like that (if possible) into a... | If I understand you right you just want to use a '?' type of if statement:
```
$output = '<div class="w-blog-entry" style="padding:0;">
<div class="w-blog-entry-h">
<div class="l-subsection color_dark" style="background-image: url('.$the_thumbnail.'); background-... |
202,526 | <p>This thing makes my coding difficult.
Wordpress codex reasons the use of esc_url by talking vaguely about security.
But is it really worth the trouble?</p>
<p>For example, what's the important, practical security benefit by using</p>
<pre><code><?php echo esc_url( home_url( '/' ) ); ?>
</code></pre>
<p>inst... | [
{
"answer_id": 202527,
"author": "matthew",
"author_id": 52429,
"author_profile": "https://wordpress.stackexchange.com/users/52429",
"pm_score": 1,
"selected": false,
"text": "<p><a href=\"https://codex.wordpress.org/Function_Reference/esc_url\" rel=\"nofollow\">esc_url</a> is used to pr... | 2015/09/12 | [
"https://wordpress.stackexchange.com/questions/202526",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80031/"
] | This thing makes my coding difficult.
Wordpress codex reasons the use of esc\_url by talking vaguely about security.
But is it really worth the trouble?
For example, what's the important, practical security benefit by using
```
<?php echo esc_url( home_url( '/' ) ); ?>
```
instead of
```
<?php echo home_url() ?>
... | If you check the documentation on [Data Validation](https://codex.wordpress.org/Data_Validation#URLs) it has following to say about the function:
>
> Always use esc\_url when sanitizing URLs (in text nodes, attribute nodes or anywhere else). Rejects URLs that do not have one of the provided whitelisted protocols [...... |
202,550 | <p>I have been searching for several hours to find a way to embed the "Add New Post" inside a page in the front end. I read <a href="https://wordpress.stackexchange.com/questions/128288/how-can-i-place-the-add-new-post-contents-on-a-custom-page">this post</a> but sadly no answer to it. </p>
<p>I have embedded the logi... | [
{
"answer_id": 202551,
"author": "Balas",
"author_id": 17849,
"author_profile": "https://wordpress.stackexchange.com/users/17849",
"pm_score": -1,
"selected": false,
"text": "<p>You have never read the WP documentation?</p>\n\n<p>Create any template and form and when submitting the form ... | 2015/09/13 | [
"https://wordpress.stackexchange.com/questions/202550",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80301/"
] | I have been searching for several hours to find a way to embed the "Add New Post" inside a page in the front end. I read [this post](https://wordpress.stackexchange.com/questions/128288/how-can-i-place-the-add-new-post-contents-on-a-custom-page) but sadly no answer to it.
I have embedded the login form in another pag... | This is pretty simple. So simple you need to make sure your guests don't insert bad code into you DB. So read up on [Data Validation](https://codex.wordpress.org/Data_Validation) and [Validating Sanitizing and Escaping User Data](https://codex.wordpress.org/Validating_Sanitizing_and_Escaping_User_Data) before you add a... |
202,613 | <p>I've enqueued a .js file on the "Media Library" page (upload.php). I need to hide and manipulate a few of the thumbnails on the page using JS only ( I'm not looking for workarounds ). </p>
<p>The elements on the page are being rendered by backbone and I have found no way so far to hook into it. In any window/docume... | [
{
"answer_id": 202551,
"author": "Balas",
"author_id": 17849,
"author_profile": "https://wordpress.stackexchange.com/users/17849",
"pm_score": -1,
"selected": false,
"text": "<p>You have never read the WP documentation?</p>\n\n<p>Create any template and form and when submitting the form ... | 2015/09/14 | [
"https://wordpress.stackexchange.com/questions/202613",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/62861/"
] | I've enqueued a .js file on the "Media Library" page (upload.php). I need to hide and manipulate a few of the thumbnails on the page using JS only ( I'm not looking for workarounds ).
The elements on the page are being rendered by backbone and I have found no way so far to hook into it. In any window/document state, ... | This is pretty simple. So simple you need to make sure your guests don't insert bad code into you DB. So read up on [Data Validation](https://codex.wordpress.org/Data_Validation) and [Validating Sanitizing and Escaping User Data](https://codex.wordpress.org/Validating_Sanitizing_and_Escaping_User_Data) before you add a... |
202,622 | <p>I am currently in the course of migrating site content from an old pre 4.1 site to a new setup and hitting an issue with the rounding error issue of <a href="https://core.trac.wordpress.org/ticket/18532" rel="noreferrer">#18532</a> and the <a href="https://core.trac.wordpress.org/changeset/30660" rel="noreferrer">co... | [
{
"answer_id": 202907,
"author": "CK MacLeod",
"author_id": 35923,
"author_profile": "https://wordpress.stackexchange.com/users/35923",
"pm_score": 1,
"selected": false,
"text": "<p>Solving the problem globally and perfectly for ALL image files (and links) in a large site - given the pos... | 2015/09/14 | [
"https://wordpress.stackexchange.com/questions/202622",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/47733/"
] | I am currently in the course of migrating site content from an old pre 4.1 site to a new setup and hitting an issue with the rounding error issue of [#18532](https://core.trac.wordpress.org/ticket/18532) and the [corresponding fix](https://core.trac.wordpress.org/changeset/30660).
To summarize this fixed a long standi... | This is another approach than [the other answer](https://wordpress.stackexchange.com/a/206986/47733) that works when importing content with the importer and fixes the URLs once and for all. Again: This is not battle-tested but is the solution I settled on and it did work.
I prefer this as it solves the issue once and ... |
202,629 | <p>I am trying to include bootstrap only when the short-code function executes. It gets included but it affects the other tags of the theme.</p>
<p>The only way I can get around this is including bootstrap globally in the plugin's primary file. It works on the front end, making the short-code execute and display outpu... | [
{
"answer_id": 202635,
"author": "dev",
"author_id": 79859,
"author_profile": "https://wordpress.stackexchange.com/users/79859",
"pm_score": 0,
"selected": false,
"text": "<p>First outside your shortcode callback function just register the stylsheet and then in shortcode callback functio... | 2015/09/14 | [
"https://wordpress.stackexchange.com/questions/202629",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/65650/"
] | I am trying to include bootstrap only when the short-code function executes. It gets included but it affects the other tags of the theme.
The only way I can get around this is including bootstrap globally in the plugin's primary file. It works on the front end, making the short-code execute and display output with boo... | I also find the typical practice of queuing globally or from inside shortcodes problematic.
I had a similar challenge with implementing code highlight on my site — I only wanted scripts and style to load as necessary. I ended up checking content for `<pre>` tag as condition to output:
```
{% if '<pre>' in get_the_con... |
202,709 | <p>I have split my post content into mutiple pages using the <code><! - nextpage -></code> code. I want to give my paginated links their own title instead of the regular 1,2,3. How can I do this? cause on this doc <a href="https://codex.wordpress.org/Styling_Page-Links">https://codex.wordpress.org/Styling_Page-L... | [
{
"answer_id": 227012,
"author": "Sumit",
"author_id": 32475,
"author_profile": "https://wordpress.stackexchange.com/users/32475",
"pm_score": 3,
"selected": false,
"text": "<p>You can use filter <a href=\"https://developer.wordpress.org/reference/hooks/wp_link_pages_link/\"><code>wp_lin... | 2015/09/15 | [
"https://wordpress.stackexchange.com/questions/202709",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17971/"
] | I have split my post content into mutiple pages using the `<! - nextpage ->` code. I want to give my paginated links their own title instead of the regular 1,2,3. How can I do this? cause on this doc <https://codex.wordpress.org/Styling_Page-Links> it only mentions method to adding suffix or prefix. I just want to give... | Here's a way to support pagination titles of the form:
```
<!--nextpage(.*?)?-->
```
in a simlar way as the core supports `<!--more(.*?)?-->`.
Here's an example:
```
<!--nextpage Planets -->
Let's talk about the Planets
<!--nextpage Mercury -->
Exotic Mercury
<!--nextpage Venus-->
Beautiful Venus
<!--nextpage Ea... |
202,723 | <p>I have created a small custom plugin which is just an HTML form. The HTML form is <code>echo</code>'d out using PHP and it includes a small JavaScript function that I want to run on submission. I cannot get it to work, however, and I am not sure what I am doing wrong. Is it not allowed to use JavaScript in this way?... | [
{
"answer_id": 227012,
"author": "Sumit",
"author_id": 32475,
"author_profile": "https://wordpress.stackexchange.com/users/32475",
"pm_score": 3,
"selected": false,
"text": "<p>You can use filter <a href=\"https://developer.wordpress.org/reference/hooks/wp_link_pages_link/\"><code>wp_lin... | 2015/09/15 | [
"https://wordpress.stackexchange.com/questions/202723",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/66556/"
] | I have created a small custom plugin which is just an HTML form. The HTML form is `echo`'d out using PHP and it includes a small JavaScript function that I want to run on submission. I cannot get it to work, however, and I am not sure what I am doing wrong. Is it not allowed to use JavaScript in this way? If not, what ... | Here's a way to support pagination titles of the form:
```
<!--nextpage(.*?)?-->
```
in a simlar way as the core supports `<!--more(.*?)?-->`.
Here's an example:
```
<!--nextpage Planets -->
Let's talk about the Planets
<!--nextpage Mercury -->
Exotic Mercury
<!--nextpage Venus-->
Beautiful Venus
<!--nextpage Ea... |
202,742 | <p>I am creating my custom Image slider,</p>
<p>in register_post_type() -> i use : supports = "title,thumbnail";</p>
<p>i use only two thing in supports, "title,thumbnail"</p>
<p>But post-thumbnails default position is Under Publish tab.</p>
<p>Its look ugly, I want to show feature image Under title fields.
Where ... | [
{
"answer_id": 202743,
"author": "bagpipper",
"author_id": 80397,
"author_profile": "https://wordpress.stackexchange.com/users/80397",
"pm_score": -1,
"selected": false,
"text": "<p>You can simply drag the featured image under the Title field</p>\n"
},
{
"answer_id": 342721,
... | 2015/09/15 | [
"https://wordpress.stackexchange.com/questions/202742",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80320/"
] | I am creating my custom Image slider,
in register\_post\_type() -> i use : supports = "title,thumbnail";
i use only two thing in supports, "title,thumbnail"
But post-thumbnails default position is Under Publish tab.
Its look ugly, I want to show feature image Under title fields.
Where editor show, i want to show my... | Super late to the party, but well...
If you want to show your featured image right under the Post title in your Admin area, use this piece of code in your functions.php :
```
add_action('do_meta_boxes', 'my_cpt_move_meta_box');
function my_cpt_move_meta_box(){
remove_meta_box( 'postimagediv', 'post_type', 'side' ... |
202,764 | <p>I have a woocommerce setup for virtual products. All products are around 10MB and uploaded fine. I do however keep getting the following error show up when browsing the store:</p>
<pre><code>Trying to upload files larger than 128G is not allowed!
</code></pre>
<p>As you can see the file upload limit is 128GB and I... | [
{
"answer_id": 211118,
"author": "Jeff Campbell",
"author_id": 84919,
"author_profile": "https://wordpress.stackexchange.com/users/84919",
"pm_score": 1,
"selected": false,
"text": "<p>I had this problem and it turned out to be a bug with the Extra Product Options plugin. Was fixed by up... | 2015/09/15 | [
"https://wordpress.stackexchange.com/questions/202764",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/64567/"
] | I have a woocommerce setup for virtual products. All products are around 10MB and uploaded fine. I do however keep getting the following error show up when browsing the store:
```
Trying to upload files larger than 128G is not allowed!
```
As you can see the file upload limit is 128GB and I have not tried uploading ... | I had this problem and it turned out to be a bug with the Extra Product Options plugin. Was fixed by updating the plugin. |
202,800 | <p>I am trying to get a custom loop to work and I can not see why it is failing. </p>
<pre><code> $args = array( 'category_name' => 'audio', 'posts_per_page' => 6 );
$sound = new WP_Query( $args );
if( $sound->have_posts()):
while ( $sound->have_posts()) : $sound->the_post();
... | [
{
"answer_id": 211118,
"author": "Jeff Campbell",
"author_id": 84919,
"author_profile": "https://wordpress.stackexchange.com/users/84919",
"pm_score": 1,
"selected": false,
"text": "<p>I had this problem and it turned out to be a bug with the Extra Product Options plugin. Was fixed by up... | 2015/09/16 | [
"https://wordpress.stackexchange.com/questions/202800",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/14761/"
] | I am trying to get a custom loop to work and I can not see why it is failing.
```
$args = array( 'category_name' => 'audio', 'posts_per_page' => 6 );
$sound = new WP_Query( $args );
if( $sound->have_posts()):
while ( $sound->have_posts()) : $sound->the_post();
$file = get_attached_media(... | I had this problem and it turned out to be a bug with the Extra Product Options plugin. Was fixed by updating the plugin. |
202,828 | <p>I have this query so far :</p>
<pre><code> $user_args = array(
'role' => 'frontend_vendor',
'orderby' => 'display_name',
'order' => 'ASC',
'number' => $no,
'offset' => $offset
);
$user_query = new WP_Use... | [
{
"answer_id": 202835,
"author": "jas",
"author_id": 80247,
"author_profile": "https://wordpress.stackexchange.com/users/80247",
"pm_score": 0,
"selected": false,
"text": "<p>Here are below some possible options:</p>\n\n<p><a href=\"http://codex.wordpress.org/Class_Reference/WP_User_Quer... | 2015/09/16 | [
"https://wordpress.stackexchange.com/questions/202828",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80451/"
] | I have this query so far :
```
$user_args = array(
'role' => 'frontend_vendor',
'orderby' => 'display_name',
'order' => 'ASC',
'number' => $no,
'offset' => $offset
);
$user_query = new WP_User_Query( $user_args );
```
... | add this in your arguments `'query_id' => 'authors_with_posts',`
```
$user_args = array(
'role' => 'frontend_vendor',
'orderby' => 'display_name',
'query_id' => 'authors_with_posts',
'order' => 'ASC',
'number' => $no,
'offset' => $offset
);
``` |
202,833 | <p>Searching the code for related posts I found two almost identical code snippets, the only difference being that one uses echo: </p>
<pre><code>echo '<li><a href="' . get_permalink() . '" title="' . the_title_attribute() . '">' . the_title() . '</a></li>';
</code></pre>
<p>and the other does... | [
{
"answer_id": 202836,
"author": "Mayeenul Islam",
"author_id": 22728,
"author_profile": "https://wordpress.stackexchange.com/users/22728",
"pm_score": 2,
"selected": false,
"text": "<h3>First one</h3>\n\n<p>I don't know any preferred way on this, you can use both where which demands. Th... | 2015/09/16 | [
"https://wordpress.stackexchange.com/questions/202833",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80031/"
] | Searching the code for related posts I found two almost identical code snippets, the only difference being that one uses echo:
```
echo '<li><a href="' . get_permalink() . '" title="' . the_title_attribute() . '">' . the_title() . '</a></li>';
```
and the other does not:
```
<li>
<a href="<?php the_permalink() ?>"... | The main differences are: the first snippet has *html inside php* while the second one has *php inside html*. Both approaches are basically valid, both are fine.
I would however always prefer (and recommend) to have *php inside html* because chances are that a third person / designer might have less difficulties in un... |
202,834 | <p>Hi my code is below for adding shortcode in posts. when i am adding shortcode two times it shows me heading two times that i added in code "Recent Posts" is there is way to show this heading only top means one time?<a href="https://i.stack.imgur.com/RuFoO.png" rel="nofollow noreferrer"><img src="https://i.stack.img... | [
{
"answer_id": 202836,
"author": "Mayeenul Islam",
"author_id": 22728,
"author_profile": "https://wordpress.stackexchange.com/users/22728",
"pm_score": 2,
"selected": false,
"text": "<h3>First one</h3>\n\n<p>I don't know any preferred way on this, you can use both where which demands. Th... | 2015/09/16 | [
"https://wordpress.stackexchange.com/questions/202834",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/41012/"
] | Hi my code is below for adding shortcode in posts. when i am adding shortcode two times it shows me heading two times that i added in code "Recent Posts" is there is way to show this heading only top means one time?[](https://i.stack.imgur.com/RuFoO.pn... | The main differences are: the first snippet has *html inside php* while the second one has *php inside html*. Both approaches are basically valid, both are fine.
I would however always prefer (and recommend) to have *php inside html* because chances are that a third person / designer might have less difficulties in un... |
202,859 | <p>I've created two new Custom Post types using code that I've used successfully on other projects without issue. The first is called <code>top_charts</code>, the other <code>case_studies</code>, and both appear correctly in the admin menu and I can create new posts.</p>
<p>Unfortunately the new posts don't appear. I ... | [
{
"answer_id": 202861,
"author": "jas",
"author_id": 80247,
"author_profile": "https://wordpress.stackexchange.com/users/80247",
"pm_score": 6,
"selected": true,
"text": "<p>For fixing custom post not found please use below code in your <code>functions.php</code>:</p>\n<pre><code>flush_r... | 2015/09/16 | [
"https://wordpress.stackexchange.com/questions/202859",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/4109/"
] | I've created two new Custom Post types using code that I've used successfully on other projects without issue. The first is called `top_charts`, the other `case_studies`, and both appear correctly in the admin menu and I can create new posts.
Unfortunately the new posts don't appear. I just get a `404.php` response.
... | For fixing custom post not found please use below code in your `functions.php`:
```
flush_rewrite_rules( false );
```
You should only do this as a temporary measure otherwise it will run on every page load.
For more details please follow [this link](https://web.archive.org/web/20140403185155/https://nooshu.com/page... |
202,860 | <p>I'm currently writing a script that is running on a server and is supposed to get information about
a) the WordPress version
b) the plugins
c) the plugin versions.</p>
<p>The WordPress version number is no problem, but I'm not sure how to reliably obtain the required plugin information. I've located the plugin fold... | [
{
"answer_id": 202861,
"author": "jas",
"author_id": 80247,
"author_profile": "https://wordpress.stackexchange.com/users/80247",
"pm_score": 6,
"selected": true,
"text": "<p>For fixing custom post not found please use below code in your <code>functions.php</code>:</p>\n<pre><code>flush_r... | 2015/09/16 | [
"https://wordpress.stackexchange.com/questions/202860",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80462/"
] | I'm currently writing a script that is running on a server and is supposed to get information about
a) the WordPress version
b) the plugins
c) the plugin versions.
The WordPress version number is no problem, but I'm not sure how to reliably obtain the required plugin information. I've located the plugin folder (wp-con... | For fixing custom post not found please use below code in your `functions.php`:
```
flush_rewrite_rules( false );
```
You should only do this as a temporary measure otherwise it will run on every page load.
For more details please follow [this link](https://web.archive.org/web/20140403185155/https://nooshu.com/page... |
202,871 | <p>Ajax call returns 0 as output. I am sure that hook is not working and it's not calling the <code>test2</code> method. Why is <code>add_action(...</code> not working inside class in <code>functions.php</code>?</p>
<p>--------Wrap inside <code>functions.php</code> Starts-------</p>
<pre><code>class test{
public ... | [
{
"answer_id": 202893,
"author": "Prasad Nevase",
"author_id": 62283,
"author_profile": "https://wordpress.stackexchange.com/users/62283",
"pm_score": 1,
"selected": false,
"text": "<p>While I am not sure why you want to do it like this, please find below the working code. Please note th... | 2015/09/16 | [
"https://wordpress.stackexchange.com/questions/202871",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80467/"
] | Ajax call returns 0 as output. I am sure that hook is not working and it's not calling the `test2` method. Why is `add_action(...` not working inside class in `functions.php`?
--------Wrap inside `functions.php` Starts-------
```
class test{
public function __construct() {
add_action( 'wp_ajax_test2', arr... | While I am not sure why you want to do it like this, please find below the working code. Please note the comments in line. I hope this helps.
```
class test{
public function __construct() {
add_action( 'wp_ajax_test2', array( $this, 'test2' ) );
/* Front end ajax needs this. */
add_action(... |
202,872 | <p>I have a site that needs to migrate from WP E-Commerce to WooCommerce.</p>
<p>I'm trying to use <code>WP All Import Pro</code> + <code>WP All Import Woocommerce add on</code> to do this.</p>
<p>I exported the WP E-Commerce products in an XML file, and imported the XML file into WooCommerce products using WP All Im... | [
{
"answer_id": 202878,
"author": "Manny Fleurmond",
"author_id": 2234,
"author_profile": "https://wordpress.stackexchange.com/users/2234",
"pm_score": 2,
"selected": false,
"text": "<p>There are two functions you can use for this: <code>wp_get_attachment_url</code> to get the full sized ... | 2015/09/16 | [
"https://wordpress.stackexchange.com/questions/202872",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/3206/"
] | I have a site that needs to migrate from WP E-Commerce to WooCommerce.
I'm trying to use `WP All Import Pro` + `WP All Import Woocommerce add on` to do this.
I exported the WP E-Commerce products in an XML file, and imported the XML file into WooCommerce products using WP All Import.
It works fine, except I can't ge... | There are two functions you can use for this: `wp_get_attachment_url` to get the full sized image or `wp_get_attachment_thumb_url`, which gets the url of the thumbnail of that attachment. Either function takes the attachment id as the sole argument:
```
$attachment_id= 25;
//Get the full url
$url = wp_get_attachment_u... |
202,873 | <p>I want to create a new order programatically.</p>
<p>This code works well with simple product,</p>
<pre><code> $product = get_product($product_id);
$order = wc_create_order();
$order->add_product( $product , 1 );
$order->calculate_totals();
// assign the order to the current user
updat... | [
{
"answer_id": 212885,
"author": "osos",
"author_id": 12185,
"author_profile": "https://wordpress.stackexchange.com/users/12185",
"pm_score": 0,
"selected": false,
"text": "<p>Here is an example </p>\n\n<pre><code> $order_data = array(\n 'status' => 'completed',\n ... | 2015/09/16 | [
"https://wordpress.stackexchange.com/questions/202873",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/55159/"
] | I want to create a new order programatically.
This code works well with simple product,
```
$product = get_product($product_id);
$order = wc_create_order();
$order->add_product( $product , 1 );
$order->calculate_totals();
// assign the order to the current user
update_post_meta($order->id, '_c... | Here's my code for creating a subscription -- it took a lot of trial and error to figure it all out. Best of luck!
```
function create_test_sub() {
$email = 'test@test.com';
$start_date = '2015-01-01 00:00:00';
$address = array(
'first_name' => 'Jeremy',
'last_name' => 'Test',
'... |
202,958 | <p>I have created the following action:</p>
<pre><code>add_action( 'test_action', 'test_action' );
function test_action() {
error_log( 'test_action' );
}
</code></pre>
<p>And am calling it like this:</p>
<pre><code>error_log( 'send_test_email_in_background:START' );
wp_schedule_single_event( time(), 'test_acti... | [
{
"answer_id": 202965,
"author": "TheDeadMedic",
"author_id": 1685,
"author_profile": "https://wordpress.stackexchange.com/users/1685",
"pm_score": 1,
"selected": false,
"text": "<p>Because you're <em>scheduling</em> the event - even though it's set to run immediately (i.e. with <code>ti... | 2015/09/17 | [
"https://wordpress.stackexchange.com/questions/202958",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/74497/"
] | I have created the following action:
```
add_action( 'test_action', 'test_action' );
function test_action() {
error_log( 'test_action' );
}
```
And am calling it like this:
```
error_log( 'send_test_email_in_background:START' );
wp_schedule_single_event( time(), 'test_action' );
error_log( 'send_test_email_i... | Because you're *scheduling* the event - even though it's set to run immediately (i.e. with `time()`), it won't fire until a second request.
So that log output is entirely expected. Try running it again, removing the code, then run once more - you should get:
```
[time] test_action
``` |
202,988 | <p>I'm trying to hook up some JS so that when the featured image upload box is opened and an image selected I can use Vibrant.js to analyse the colours of the selected image. The hurdle I've encountered is that I can't find any particular event to bind my function to. I've looked at various tutorials regarding the <cod... | [
{
"answer_id": 203417,
"author": "Dre",
"author_id": 60767,
"author_profile": "https://wordpress.stackexchange.com/users/60767",
"pm_score": 4,
"selected": true,
"text": "<p>After some digging I discovered that wp.media.featuredImage.frame() was what I was looking for:</p>\n\n<pre><code>... | 2015/09/17 | [
"https://wordpress.stackexchange.com/questions/202988",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/60767/"
] | I'm trying to hook up some JS so that when the featured image upload box is opened and an image selected I can use Vibrant.js to analyse the colours of the selected image. The hurdle I've encountered is that I can't find any particular event to bind my function to. I've looked at various tutorials regarding the `wp.med... | After some digging I discovered that wp.media.featuredImage.frame() was what I was looking for:
```
wp.media.featuredImage.frame().on('open',function() {
// Clever JS here
});
```
I then discovered that the `select` event fires once you've clicked on the 'Set featured image' button, *not* when you've clicked on ... |
202,991 | <p>I am trying to make my own version <a href="http://demo.codestag.com/ink/" rel="nofollow">of this</a> I've implemented bootstrap grid in my attempt. I'm very close, but the <code><div class="row"></code> being looped is causing problems.</p>
<p>I want to just be able to build my html structure with bootstrap ... | [
{
"answer_id": 202996,
"author": "Rarst",
"author_id": 847,
"author_profile": "https://wordpress.stackexchange.com/users/847",
"pm_score": 0,
"selected": false,
"text": "<p>The common loop implementation loops for <em>every</em> post. It is so pervasive that it's not obvious it being ent... | 2015/09/17 | [
"https://wordpress.stackexchange.com/questions/202991",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/60779/"
] | I am trying to make my own version [of this](http://demo.codestag.com/ink/) I've implemented bootstrap grid in my attempt. I'm very close, but the `<div class="row">` being looped is causing problems.
I want to just be able to build my html structure with bootstrap and not rely soley on the `if` statements that contro... | ```
<?php
$counter = 1;
if(have_posts()) : while(have_posts()) : the_post();
?>
<?php
if($counter == 1) :
?>
<div class="row clear" style="margin-bottom:0px;">
<div class="col-md-12 border-12">
<a class="thumb" href="<?php the_permalink(); ?>" title="<?php the_title_... |
203,014 | <p>I've got a basic text widget and, outside the standard <code><div class="textwidget"></code> wrapper there is a <code><li id="text-5" class="widget widget_text"></code> (which I have not added when creating the sidebar in <code>functions.php</code> or added when adding a text widget from the dashboard). ... | [
{
"answer_id": 203017,
"author": "JediTricks007",
"author_id": 49017,
"author_profile": "https://wordpress.stackexchange.com/users/49017",
"pm_score": 3,
"selected": true,
"text": "<p>I think WordPress widgets create li tags on default. If you want the bullet points removed you could fi... | 2015/09/17 | [
"https://wordpress.stackexchange.com/questions/203014",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/48904/"
] | I've got a basic text widget and, outside the standard `<div class="textwidget">` wrapper there is a `<li id="text-5" class="widget widget_text">` (which I have not added when creating the sidebar in `functions.php` or added when adding a text widget from the dashboard).
i.e. the full code looks like this:
```
<li i... | I think WordPress widgets create li tags on default. If you want the bullet points removed you could fix that with a css approach.
```
.widget li {
list-style: none;
}
``` |
203,027 | <p>So I have a client who wants a little extra that is beyond capabilities of my wordpress theme that I have purchased. I know through html, css and js I can create it from scratch (they want animations and a neat looking landing page). I was wondering if there was a way or any plugins that I can use to directly create... | [
{
"answer_id": 203017,
"author": "JediTricks007",
"author_id": 49017,
"author_profile": "https://wordpress.stackexchange.com/users/49017",
"pm_score": 3,
"selected": true,
"text": "<p>I think WordPress widgets create li tags on default. If you want the bullet points removed you could fi... | 2015/09/18 | [
"https://wordpress.stackexchange.com/questions/203027",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80568/"
] | So I have a client who wants a little extra that is beyond capabilities of my wordpress theme that I have purchased. I know through html, css and js I can create it from scratch (they want animations and a neat looking landing page). I was wondering if there was a way or any plugins that I can use to directly create a ... | I think WordPress widgets create li tags on default. If you want the bullet points removed you could fix that with a css approach.
```
.widget li {
list-style: none;
}
``` |
203,062 | <p>I am a little confused by this. I have a query that finds posts within a category and date.</p>
<p>I can filter the categories, but I have no idea how to filter by date.</p>
<p>The query works. I see all of the posts I have queried, but I don't know how to filter the date. It would help if I knew what was meant to... | [
{
"answer_id": 203322,
"author": "MrFox",
"author_id": 69240,
"author_profile": "https://wordpress.stackexchange.com/users/69240",
"pm_score": 2,
"selected": true,
"text": "<p>I was going about this the wrong way around. I needed to allow the user to select the date first and then the ca... | 2015/09/18 | [
"https://wordpress.stackexchange.com/questions/203062",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/69240/"
] | I am a little confused by this. I have a query that finds posts within a category and date.
I can filter the categories, but I have no idea how to filter by date.
The query works. I see all of the posts I have queried, but I don't know how to filter the date. It would help if I knew what was meant to appear in the ur... | I was going about this the wrong way around. I needed to allow the user to select the date first and then the category.
I also needed to make the dropdown boxes auto select, so that the date search is performed first taking the user to the date archive and then the user can select the category they require.
```
<form... |
203,077 | <p>Here's the query i have used.</p>
<pre><code> <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$wp_query = new WP_Query('order=asc&orderby=meta_value&meta_key=date&posts_per_page=6&paged=' . $paged); ?>
</code></pre>
<p>Is there any way to skip the first 3 posts only in ... | [
{
"answer_id": 203078,
"author": "Steed-Asprey",
"author_id": 75166,
"author_profile": "https://wordpress.stackexchange.com/users/75166",
"pm_score": 0,
"selected": false,
"text": "<p>By using the offset parameter: <a href=\"https://codex.wordpress.org/Class_Reference/WP_Query#Pagination... | 2015/09/18 | [
"https://wordpress.stackexchange.com/questions/203077",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80611/"
] | Here's the query i have used.
```
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$wp_query = new WP_Query('order=asc&orderby=meta_value&meta_key=date&posts_per_page=6&paged=' . $paged); ?>
```
Is there any way to skip the first 3 posts only in the first page (?paged=1) and not the other page... | For skipping the post just use offset parameter in wp\_query.
To display latest three post :
```
<?php
$latestpost = new WP_Query('order=asc&orderby=meta_value&meta_key=date&posts_per_page=3');
//Here add loop to display posts like
while($latestpost->have_posts()) : $latestpost->the_post();
the_title();
the_conte... |
203,091 | <p>Lets say you have a custom template and you want to implement a title of Wordpress template
for section /category/general where general is a category name . </p>
<p>How to implement category page titile for this page .</p>
<p>I tried with </p>
<pre><code> <h2><a href="#" rel="bookmark" title="Perm... | [
{
"answer_id": 203078,
"author": "Steed-Asprey",
"author_id": 75166,
"author_profile": "https://wordpress.stackexchange.com/users/75166",
"pm_score": 0,
"selected": false,
"text": "<p>By using the offset parameter: <a href=\"https://codex.wordpress.org/Class_Reference/WP_Query#Pagination... | 2015/09/18 | [
"https://wordpress.stackexchange.com/questions/203091",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80617/"
] | Lets say you have a custom template and you want to implement a title of Wordpress template
for section /category/general where general is a category name .
How to implement category page titile for this page .
I tried with
```
<h2><a href="#" rel="bookmark" title="Permanent Link to <?php the_title_attribute();... | For skipping the post just use offset parameter in wp\_query.
To display latest three post :
```
<?php
$latestpost = new WP_Query('order=asc&orderby=meta_value&meta_key=date&posts_per_page=3');
//Here add loop to display posts like
while($latestpost->have_posts()) : $latestpost->the_post();
the_title();
the_conte... |
203,092 | <p>i make a custom post type in WordPress and i also make its separate two pages single-acme_product.php, archive-acme_product.php but the issue is when i upload the post from custom post type its show index.php </p>
<p>here is my code of function </p>
<pre><code>function new_post_type_wp(){
register_post_type(... | [
{
"answer_id": 203098,
"author": "user57831",
"author_id": 57831,
"author_profile": "https://wordpress.stackexchange.com/users/57831",
"pm_score": -1,
"selected": false,
"text": "<p>Alright, if I am not wrong with your request, below solutions may help.\n1. make you sing-acme_product.php... | 2015/09/18 | [
"https://wordpress.stackexchange.com/questions/203092",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/79858/"
] | i make a custom post type in WordPress and i also make its separate two pages single-acme\_product.php, archive-acme\_product.php but the issue is when i upload the post from custom post type its show index.php
here is my code of function
```
function new_post_type_wp(){
register_post_type('acme_product',
... | Since WordPress is having trouble recognizing your custom template files, you could use this instead.
Insert into your `single.php` file. Based on your description above, it sounds like you don't have a `single.php` file so you will likely have to create one. If you do already have a `single.php` file then there is li... |
203,094 | <p>My blog (Jetpack) sends out <code>512x512</code> favicon as <code>og:image</code>, because theme used does not support featured images and there are no images / gallery in the post itself. I'm forced to use favicons that large, because Wordpress / theme says:</p>
<blockquote>
<p>The Site Icon is used as a browser... | [
{
"answer_id": 228606,
"author": "Gareth Gillman",
"author_id": 33936,
"author_profile": "https://wordpress.stackexchange.com/users/33936",
"pm_score": 1,
"selected": false,
"text": "<p>If you know the name of the function that is adding the meta tag (and it's added in it's own).</p>\n\n... | 2015/09/18 | [
"https://wordpress.stackexchange.com/questions/203094",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/17323/"
] | My blog (Jetpack) sends out `512x512` favicon as `og:image`, because theme used does not support featured images and there are no images / gallery in the post itself. I'm forced to use favicons that large, because Wordpress / theme says:
>
> The Site Icon is used as a browser and app icon for your site. Icons must be... | >
> Probably through Jetpack, yet I'm not sure
>
>
>
Looking at your site now I can say that those open graph tags are from `Jetpack` Plugin.
---
If there is no image available in the post , Jetpack adds site-icon/favicon as the default one.
We can control output of tags using filters
* **`jetpack_open_graph_t... |
203,099 | <p>I'm building a Wordpress plugin in which I need to get the <strong>HOME page ID value</strong>.</p>
<p>Do you know how can I get it?</p>
<p>I know that we can get the current ID with <code>the_ID()</code> or <code>get_the_ID()</code> function, but I need specificly the <strong>HOME page ID value</strong>.</p>
<p>... | [
{
"answer_id": 203104,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 3,
"selected": false,
"text": "<p>If by Home Page you mean the page designated as the Posts page, the ID is stored in the option <code>page_for_post... | 2015/09/18 | [
"https://wordpress.stackexchange.com/questions/203099",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/77424/"
] | I'm building a Wordpress plugin in which I need to get the **HOME page ID value**.
Do you know how can I get it?
I know that we can get the current ID with `the_ID()` or `get_the_ID()` function, but I need specificly the **HOME page ID value**.
My plugin is located at the following directory path:
```
wp-content/pl... | `$pageID = get_option('page_on_front');` should get you the Page ID of the page set at 'Front Page' in WordPress options. |
203,112 | <p>Below code adds <code>My Page</code> button in Admin Menu. It will take you to your author page when you click on it. However, it also opens up new page(Empty page).</p>
<p>I want it to just take you to author page and do not open a new page in backend.
How do I achieve that? I also make this menu show up for all u... | [
{
"answer_id": 203104,
"author": "Milo",
"author_id": 4771,
"author_profile": "https://wordpress.stackexchange.com/users/4771",
"pm_score": 3,
"selected": false,
"text": "<p>If by Home Page you mean the page designated as the Posts page, the ID is stored in the option <code>page_for_post... | 2015/09/18 | [
"https://wordpress.stackexchange.com/questions/203112",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/74171/"
] | Below code adds `My Page` button in Admin Menu. It will take you to your author page when you click on it. However, it also opens up new page(Empty page).
I want it to just take you to author page and do not open a new page in backend.
How do I achieve that? I also make this menu show up for all user roles(it only sho... | `$pageID = get_option('page_on_front');` should get you the Page ID of the page set at 'Front Page' in WordPress options. |
203,114 | <p>I'm using <code>get_next_post_link()</code> and <code>get_previous_post_link()</code> within the loop but the returned posts are not correct.</p>
<p><code>get_next_post_link()</code> shows the previous post and <code>get_previous_post_link()</code> gives the current post. Below the context of these links:</p>
<pre... | [
{
"answer_id": 203118,
"author": "bart",
"author_id": 80625,
"author_profile": "https://wordpress.stackexchange.com/users/80625",
"pm_score": 0,
"selected": false,
"text": "<p>This has been solved by changing <code>Site Address (URL)</code> in <code>Settings > General</code> to the pa... | 2015/09/18 | [
"https://wordpress.stackexchange.com/questions/203114",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80625/"
] | I'm using `get_next_post_link()` and `get_previous_post_link()` within the loop but the returned posts are not correct.
`get_next_post_link()` shows the previous post and `get_previous_post_link()` gives the current post. Below the context of these links:
```
$args['name'] = $postname;
$query = new WP_Query($args);
... | This has been solved by changing `Site Address (URL)` in `Settings > General` to the path that matches with the posts's path. I was pulling in posts from another location in my website that did not match with the original (default) path of the post. |
203,128 | <p>So for previous and next posts I used this from wordpress codex</p>
<pre><code><div class="navigation">
<p>
<?php posts_nav_link('&#8734;','Go Forward In Time','Go Back in Time'); ?>
</p>
</div>
</code></pre>
<p>I want to change that.. in the wp-admin, I used on se... | [
{
"answer_id": 221915,
"author": "adiian",
"author_id": 91353,
"author_profile": "https://wordpress.stackexchange.com/users/91353",
"pm_score": 1,
"selected": false,
"text": "<p>That is practically the only option, to disable the php error/warning logging. There are 2 options to do it an... | 2015/09/19 | [
"https://wordpress.stackexchange.com/questions/203128",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/78209/"
] | So for previous and next posts I used this from wordpress codex
```
<div class="navigation">
<p>
<?php posts_nav_link('∞','Go Forward In Time','Go Back in Time'); ?>
</p>
</div>
```
I want to change that.. in the wp-admin, I used on settings -> reading -> Blog pages show at most = 5 so I wanted... | PHP files in the wp-includes directory should not be accessible from the outside, they should only be included by wordpress code. Therefor an easy fix to this is to use .htaccess rules to block access to \*.php files that are under the wp-includes directory |
203,144 | <p>I think I have a great idea to make my site load faster in mobile: <em>"don't load the custom fonts in small screens"</em></p>
<p>I know how to style/change the font used depending on screen size with media queries and css.
What I don't know is how to prevent the custom fonts from loading in small screens.
I use go... | [
{
"answer_id": 203148,
"author": "Robert hue",
"author_id": 22461,
"author_profile": "https://wordpress.stackexchange.com/users/22461",
"pm_score": 3,
"selected": true,
"text": "<p>WordPress has <a href=\"https://codex.wordpress.org/Function_Reference/wp_is_mobile\" rel=\"nofollow\"><cod... | 2015/09/19 | [
"https://wordpress.stackexchange.com/questions/203144",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80031/"
] | I think I have a great idea to make my site load faster in mobile: *"don't load the custom fonts in small screens"*
I know how to style/change the font used depending on screen size with media queries and css.
What I don't know is how to prevent the custom fonts from loading in small screens.
I use google fonts and I ... | WordPress has [`wp_is_mobile()`](https://codex.wordpress.org/Function_Reference/wp_is_mobile) function to detect mobile and handheld devices. You can use that to define your enqueue function to load fonts conditionally.
You can enqueue fonts for non mobile devices like this.
```
function my_enqueue_function() {
if... |
203,208 | <p>I would like to change the image sizes for "medium" and "large". </p>
<p>I did change the sizes in Settings > Media </p>
<p><a href="https://i.stack.imgur.com/yD7ro.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yD7ro.png" alt="enter image description here"></a></p>
<p>This however does not se... | [
{
"answer_id": 203210,
"author": "tillinberlin",
"author_id": 26059,
"author_profile": "https://wordpress.stackexchange.com/users/26059",
"pm_score": 0,
"selected": false,
"text": "<p>Solved: The new / custom sizes are only available for new images… </p>\n"
},
{
"answer_id": 2032... | 2015/09/20 | [
"https://wordpress.stackexchange.com/questions/203208",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/26059/"
] | I would like to change the image sizes for "medium" and "large".
I did change the sizes in Settings > Media
[](https://i.stack.imgur.com/yD7ro.png)
This however does not seem to have any effect on the settings I see when I edit or insert an image:... | Your image sizes need to be regenerated, as for the images to have different sizes they need to be cropped from the original and written to an actual file, whereas the settings only updates the settings, so will only affect future uploads. The [Regenerate Thumbnails](https://wordpress.org/plugins/regenerate-thumbnails/... |
203,209 | <p>I am submitting my theme to WordPress.org. To make it compatible with WordPress 4.1 and greater, I replaced <code>wptitle()</code> tag with <code>add_theme_support( 'title-tag' )</code> but now the error has changed to following:</p>
<pre><code>REQUIRED: The <title> tags can only contain a call to wp_title().... | [
{
"answer_id": 203215,
"author": "Caspar",
"author_id": 27191,
"author_profile": "https://wordpress.stackexchange.com/users/27191",
"pm_score": 2,
"selected": false,
"text": "<p><code>add_theme_support( 'title-tag' )</code> doesn't belong in your header template. It belongs in your <code... | 2015/09/20 | [
"https://wordpress.stackexchange.com/questions/203209",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/-1/"
] | I am submitting my theme to WordPress.org. To make it compatible with WordPress 4.1 and greater, I replaced `wptitle()` tag with `add_theme_support( 'title-tag' )` but now the error has changed to following:
```
REQUIRED: The <title> tags can only contain a call to wp_title(). Use the wp_title filter to modify the out... | `add_theme_support( 'title-tag' )` doesn't belong in your header template. It belongs in your `functions.php` file. Usually, it's best to wrap it in it's own function and hook it to `after_setup_theme` in order to allow plugins and child themes to override it later if they need to. So...
```
function wpse_add_title_su... |
203,223 | <p>I am using the following code to display media files on a custom static page. Files display properly but pagination is <strong>not</strong> working. How can I solve this issue?</p>
<p>Following code shows the media files:</p>
<pre><code>$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = ... | [
{
"answer_id": 203248,
"author": "Asadullah",
"author_id": 30852,
"author_profile": "https://wordpress.stackexchange.com/users/30852",
"pm_score": 0,
"selected": false,
"text": "<p>Pagination is always based on main query that is in your case is static page and has only one page hence no... | 2015/09/20 | [
"https://wordpress.stackexchange.com/questions/203223",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80689/"
] | I am using the following code to display media files on a custom static page. Files display properly but pagination is **not** working. How can I solve this issue?
Following code shows the media files:
```
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'post_type' => 'at... | Dear I have wasted my week on this problem, basically when you select static page as your home page in setting->reading of wordpress the complete behavior of listing things are changed, basically static pages are never meant for pagination the fact is when you call the $paged variable it will always return zero even if... |
203,224 | <p>There seems to be a ton of information on checking a <code>meta_key</code> against an array of <code>meta_values</code>, but I want to do the opposite. </p>
<p>I have a site with projects, and press reviews. When the client adds a review, they have a custom field (ACF) to select the project it relates to from a lis... | [
{
"answer_id": 203235,
"author": "Khaled Sadek",
"author_id": 75122,
"author_profile": "https://wordpress.stackexchange.com/users/75122",
"pm_score": 0,
"selected": false,
"text": "<p>I believe that you should use <code>IN</code> at <code>compare</code>\nbut you said this's not working.\... | 2015/09/20 | [
"https://wordpress.stackexchange.com/questions/203224",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80687/"
] | There seems to be a ton of information on checking a `meta_key` against an array of `meta_values`, but I want to do the opposite.
I have a site with projects, and press reviews. When the client adds a review, they have a custom field (ACF) to select the project it relates to from a list.
I am now trying to display ... | The solution was that I need to compare the literal value of `$projectID`, so that `LIKE` compares an exact string instead of just numbers. To make `$projectID` literal, it needs to be wrapped in quotes.
So, I changed this line:
`'value' => $projectID,`
to:
`'value' => '"'.$projectID.'"',`
Which solves the problem... |
203,229 | <p>I have this plugin I created that has a custom post type and a template file that renders the posts.
I want to be able to render the template in any page using a short code. So what I created was this piece of code which I am sure is wrong and would totally appreciate it if someone could answer how I am supposed to... | [
{
"answer_id": 203230,
"author": "Prasad Nevase",
"author_id": 62283,
"author_profile": "https://wordpress.stackexchange.com/users/62283",
"pm_score": 0,
"selected": false,
"text": "<p>Please try using <code>get_template_part('timelines');</code> instead of <code>locate_template(plugin_d... | 2015/09/20 | [
"https://wordpress.stackexchange.com/questions/203229",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/48389/"
] | I have this plugin I created that has a custom post type and a template file that renders the posts.
I want to be able to render the template in any page using a short code. So what I created was this piece of code which I am sure is wrong and would totally appreciate it if someone could answer how I am supposed to re... | [`locate_template()`](http://wpseek.com/function/locate_template/) only look for a specific template in themes, not in plugins, so your function wil never work. This also goes for [`get_template_part()`](https://developer.wordpress.org/reference/functions/get_template_part/) which is in essence just a wrapper function ... |
203,239 | <p>Ive got a CPT and in my CPT's argument I am calling the taxonomy <code>post_tag</code>. When I create a <code>tag.php</code> file it doesn't show any of the posts for said tag. My <code>tag.php</code>:</p>
<pre><code><?php get_header(); ?>
<section class="row">
<div class="col-md-7">... | [
{
"answer_id": 203241,
"author": "user9447",
"author_id": 25271,
"author_profile": "https://wordpress.stackexchange.com/users/25271",
"pm_score": 4,
"selected": true,
"text": "<p>I figured it out thanks to <a href=\"https://wordpress.stackexchange.com/questions/203239/tag-php-not-display... | 2015/09/20 | [
"https://wordpress.stackexchange.com/questions/203239",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/25271/"
] | Ive got a CPT and in my CPT's argument I am calling the taxonomy `post_tag`. When I create a `tag.php` file it doesn't show any of the posts for said tag. My `tag.php`:
```
<?php get_header(); ?>
<section class="row">
<div class="col-md-7">
<p>Tag: <?php single_tag_title(); ?></p>
... | I figured it out thanks to [Pieter's comment](https://wordpress.stackexchange.com/questions/203239/tag-php-not-displaying-posts-with-the-tag#comment295054_203239):
In `functions.php` I added:
```
function tag_filter($query) {
if ( !is_admin() && $query->is_main_query() ) {
if ($query->is_tag) {
$query->se... |
203,240 | <p>I need to sort my products by rating in a wp_query loop:</p>
<p>this is my code:</p>
<pre><code>switch($ordering){
case 'default':
$meta_key = '';
$order = 'asc';
$orderby = 'menu_order title';
break;
case 'popularity':
$meta_key = '';
$order = 'desc';
... | [
{
"answer_id": 219219,
"author": "Shamar Kellman",
"author_id": 88986,
"author_profile": "https://wordpress.stackexchange.com/users/88986",
"pm_score": 3,
"selected": false,
"text": "<p>You should use <code>'orderby' => 'meta_value_num'</code> and <code>'meta_key' => 'rating'</c... | 2015/09/20 | [
"https://wordpress.stackexchange.com/questions/203240",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/18072/"
] | I need to sort my products by rating in a wp\_query loop:
this is my code:
```
switch($ordering){
case 'default':
$meta_key = '';
$order = 'asc';
$orderby = 'menu_order title';
break;
case 'popularity':
$meta_key = '';
$order = 'desc';
$orderby = 'total_... | You should use `'orderby' => 'meta_value_num'` and `'meta_key' => 'rating'` as specified by the WordPress Codec. Using `meta_value_num` with the assumption your ratings are numeric values
Reference: [Orderby Parameters](https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters) |
203,252 | <p>I have just started playing with the WP REST API and found that when querying posts that there is a limit of 10 post per page unless specified. What I would like to know if is is possible to return the total number of post in a category though meta data or something similar?</p>
| [
{
"answer_id": 236877,
"author": "Sdghasemi",
"author_id": 101489,
"author_profile": "https://wordpress.stackexchange.com/users/101489",
"pm_score": -1,
"selected": false,
"text": "<p>A bit late to the party but in case someone trying to find a solution to do such thing with WP REST API ... | 2015/09/20 | [
"https://wordpress.stackexchange.com/questions/203252",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80701/"
] | I have just started playing with the WP REST API and found that when querying posts that there is a limit of 10 post per page unless specified. What I would like to know if is is possible to return the total number of post in a category though meta data or something similar? | To just know the number of posts in a category, its endpoint returns that number straightforward, in example:
```
curl http://wired.com/wp-json/wp/v2/categories/24
```
In the resource returned, the `count` field says: 486
Which is the same number the metadata says about the total number of posts, if you request the... |
203,270 | <p>I am trying to add css code into head tag. the css style is from shortcodes. title text from shortcode and title color / font size.. etc.
This is an example.</p>
<pre><code><html>
<head>
<?php wp_head(); ?>
.................. (some style, js) ..................
/* I want to put all of css styles ... | [
{
"answer_id": 203272,
"author": "Ahmar Ali",
"author_id": 45901,
"author_profile": "https://wordpress.stackexchange.com/users/45901",
"pm_score": 0,
"selected": false,
"text": "<p>Create a new folder in your theme for CSS. Put your custom styling in a separate file and save it in css fo... | 2015/09/21 | [
"https://wordpress.stackexchange.com/questions/203270",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/34463/"
] | I am trying to add css code into head tag. the css style is from shortcodes. title text from shortcode and title color / font size.. etc.
This is an example.
```
<html>
<head>
<?php wp_head(); ?>
.................. (some style, js) ..................
/* I want to put all of css styles into head tag from into body tag... | It's not working because you're calling add\_action after the actual action is fired. If you move the action declaration before wp\_head() it will work:
```
<html>
<head>
<?php
add_action( 'wp_head', function () {
echo '<style type="text/css">.sc_title {color:#fff; font-weight:600;}</style>';... |
203,277 | <p>In my site I've does some coding based on the category like <code>in_category('featured')</code> do something. Now, this is only applicable to posts only. Also the posts which is associated with <code>featured</code> category is also associated with other category too. As it is only associated with <code>featured</c... | [
{
"answer_id": 203281,
"author": "Alessandro Benoit",
"author_id": 16637,
"author_profile": "https://wordpress.stackexchange.com/users/16637",
"pm_score": 2,
"selected": true,
"text": "<p>Replace all the call to in_category('featured') with the custom function inCategory('featured'), dec... | 2015/09/21 | [
"https://wordpress.stackexchange.com/questions/203277",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/50584/"
] | In my site I've does some coding based on the category like `in_category('featured')` do something. Now, this is only applicable to posts only. Also the posts which is associated with `featured` category is also associated with other category too. As it is only associated with `featured` category to show up with specia... | Replace all the call to in\_category('featured') with the custom function inCategory('featured'), declare it on your functions.php:
```
/**
* @param string $category
*
* @return bool
*/
function inCategory($category)
{
global $wpdb, $post;
if ( ! $post) {
return false;
}
$query = $wpdb->p... |
203,279 | <p>Change title separator.</p>
<p>I'm working with the underscores starter theme. I want to make a small change to the title. Change the separator from
"Post title | site name" to "Post title - site name"</p>
<p>The simple way of doing this was to put </p>
<pre><code> <title><?php wp_title('-', true, 'righ... | [
{
"answer_id": 203285,
"author": "cybmeta",
"author_id": 37428,
"author_profile": "https://wordpress.stackexchange.com/users/37428",
"pm_score": 5,
"selected": true,
"text": "<h2>UPDATE for WordPress 4.4</h2>\n\n<p>Since WordPress 4.4 the <code>wp_title</code> filter doesn't work because... | 2015/09/21 | [
"https://wordpress.stackexchange.com/questions/203279",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80031/"
] | Change title separator.
I'm working with the underscores starter theme. I want to make a small change to the title. Change the separator from
"Post title | site name" to "Post title - site name"
The simple way of doing this was to put
```
<title><?php wp_title('-', true, 'right' ); ?><?php bloginfo( 'name' ); ?><... | UPDATE for WordPress 4.4
------------------------
Since WordPress 4.4 the `wp_title` filter doesn't work because `wp_title()` function is not used in core anymore. That function was marked as deprecated, then reinstated until new notice but [theme authors are discouraged from using it](https://make.wordpress.org/core/... |
203,352 | <p>I am using <a href="https://github.com/WebDevStudios/CMB2" rel="nofollow">CMB2</a> for metabox on custom posts. I am adding a metabox by using code below:</p>
<pre><code>$cmb_demo->add_field( array(
'name' => __( 'Test Text', 'cmb2' ),
'desc' => __( 'field description (optional)', 'cmb2... | [
{
"answer_id": 220702,
"author": "Justin Sternberg",
"author_id": 45740,
"author_profile": "https://wordpress.stackexchange.com/users/45740",
"pm_score": 2,
"selected": false,
"text": "<p>You need to replace the <code>get_option</code> call with a call to <code>get_post_meta</code>:</p>\... | 2015/09/22 | [
"https://wordpress.stackexchange.com/questions/203352",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/12198/"
] | I am using [CMB2](https://github.com/WebDevStudios/CMB2) for metabox on custom posts. I am adding a metabox by using code below:
```
$cmb_demo->add_field( array(
'name' => __( 'Test Text', 'cmb2' ),
'desc' => __( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'text',
't... | The best way to do this is by using JavaScript and there is a couple of CMB2 plugins let you do that easily:
1. [CMB2 Conditional](https://github.com/jcchavezs/cmb2-conditionals)
2. [CMB2 Conditional Logic](https://github.com/awran5/CMB2-conditional-logic) |
203,406 | <p>I have a <code>front-page.php</code> to create the index page template and a <code>page-blog.php</code> to create the blog template. My styles are added using <code>wp_enqueue_style</code> in my <code>functions.php</code>, but I'd like to use different items (css and js) on <code>page-blog.php</code>. Is it possible... | [
{
"answer_id": 203407,
"author": "WordPress Mike",
"author_id": 33921,
"author_profile": "https://wordpress.stackexchange.com/users/33921",
"pm_score": 1,
"selected": false,
"text": "<p>You should use a conditional based on the page template. </p>\n\n<pre><code>if ( is_page_template( 'p... | 2015/09/22 | [
"https://wordpress.stackexchange.com/questions/203406",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/78432/"
] | I have a `front-page.php` to create the index page template and a `page-blog.php` to create the blog template. My styles are added using `wp_enqueue_style` in my `functions.php`, but I'd like to use different items (css and js) on `page-blog.php`. Is it possible? | When using hooks such as [`wp_enqueue_scripts`](https://codex.wordpress.org/Function_Reference/wp_enqueue_script) you have access to [Conditional Tags](https://codex.wordpress.org/Conditional_Tags). This allows you to only enqueue certain things on certain pages, templates, taxonomies, etc.
By default, WordPress accep... |
203,434 | <p>I want to be able to reference the theme directory in a page/post using php code. I don't know how to do this with WordPress but other CMS use something like a <code>path_to_home</code> php variable like </p>
<pre><code><img src="<?php path_to_home() . 'images/image.jpb'; ?>">
</code></pre>
<p>In WP I ... | [
{
"answer_id": 203407,
"author": "WordPress Mike",
"author_id": 33921,
"author_profile": "https://wordpress.stackexchange.com/users/33921",
"pm_score": 1,
"selected": false,
"text": "<p>You should use a conditional based on the page template. </p>\n\n<pre><code>if ( is_page_template( 'p... | 2015/09/22 | [
"https://wordpress.stackexchange.com/questions/203434",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/45709/"
] | I want to be able to reference the theme directory in a page/post using php code. I don't know how to do this with WordPress but other CMS use something like a `path_to_home` php variable like
```
<img src="<?php path_to_home() . 'images/image.jpb'; ?>">
```
In WP I tried
```
<img class="first-slide" src="<?php ge... | When using hooks such as [`wp_enqueue_scripts`](https://codex.wordpress.org/Function_Reference/wp_enqueue_script) you have access to [Conditional Tags](https://codex.wordpress.org/Conditional_Tags). This allows you to only enqueue certain things on certain pages, templates, taxonomies, etc.
By default, WordPress accep... |
203,444 | <p>Is there a way to count the number of posts / pages via the WordPress API?</p>
<p>I'm wanting to insert a post then check, using the API, that the count has gone up by 1.</p>
<p>I've looked at <a href="http://codex.wordpress.org/XML-RPC_WordPress_API/Posts#wp.getPosts" rel="nofollow">http://codex.wordpress.org/XML... | [
{
"answer_id": 223214,
"author": "Tim",
"author_id": 56882,
"author_profile": "https://wordpress.stackexchange.com/users/56882",
"pm_score": 3,
"selected": true,
"text": "<p>Assuming you are using Linux or OS X, the easiest way is probably to use wp-cli (if present in your WordPress inst... | 2015/09/22 | [
"https://wordpress.stackexchange.com/questions/203444",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/48904/"
] | Is there a way to count the number of posts / pages via the WordPress API?
I'm wanting to insert a post then check, using the API, that the count has gone up by 1.
I've looked at <http://codex.wordpress.org/XML-RPC_WordPress_API/Posts#wp.getPosts> | Assuming you are using Linux or OS X, the easiest way is probably to use wp-cli (if present in your WordPress installation) to return a list of all posts:
```
wp-cli post list
```
Then pipe it to the word count tool to get the number of lines:
```
wc -l
```
Finally, deduct one to take care of the header line wh... |
203,487 | <p>I was using the following: <code>get_home_path();</code> in my functions.php as referenced <a href="https://codex.wordpress.org/Function_Reference/get_home_path" rel="nofollow noreferrer">in the docs</a> – but I get the error:</p>
<pre><code>Call to undefined function get_home_path() in ...
</code></pre>
<p>I'd like... | [
{
"answer_id": 286097,
"author": "Steven",
"author_id": 13118,
"author_profile": "https://wordpress.stackexchange.com/users/13118",
"pm_score": 0,
"selected": false,
"text": "<p>Perhaps this issue is that <code>get_home_path()</code> can only be used in the admin?\nAs it says in small le... | 2015/09/23 | [
"https://wordpress.stackexchange.com/questions/203487",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/27866/"
] | I was using the following: `get_home_path();` in my functions.php as referenced [in the docs](https://codex.wordpress.org/Function_Reference/get_home_path) – but I get the error:
```
Call to undefined function get_home_path() in ...
```
I'd like to include a file using it. I noticed there is also the constant `ABSPA... | [`get_home_path()` only works when WP admin scripts are loaded.](https://codex.wordpress.org/Function_Reference/get_home_path)
`ABSPATH` is [defined in wp-config.php](https://core.trac.wordpress.org/browser/trunk/wp-config-sample.php#L84) so works anytime after the config file is loaded, so it should be totally fine f... |
203,489 | <p>I want to add a media uploader to a plugin.</p>
<p>I have found and read
<a href="https://stackoverflow.com/a/28549014/3115317">This</a></p>
<p>It does shows the media uploader and it let's me select an image but as it uploads it gives me some crappy error: <code>Error occurred during upload. Try again later.</cod... | [
{
"answer_id": 203497,
"author": "dev",
"author_id": 79859,
"author_profile": "https://wordpress.stackexchange.com/users/79859",
"pm_score": 3,
"selected": true,
"text": "<p>Try using this code:</p>\n<pre><code>define("ME_URL", rtrim(WP_PLUGIN_URL,'/') . '/' . basename(dirname(... | 2015/09/23 | [
"https://wordpress.stackexchange.com/questions/203489",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/52240/"
] | I want to add a media uploader to a plugin.
I have found and read
[This](https://stackoverflow.com/a/28549014/3115317)
It does shows the media uploader and it let's me select an image but as it uploads it gives me some crappy error: `Error occurred during upload. Try again later.`
This might be slight off because ... | Try using this code:
```
define("ME_URL", rtrim(WP_PLUGIN_URL,'/') . '/' . basename(dirname(__FILE__)));
define("ME_DIR", rtrim(dirname(__FILE__), '/'));
function my_admin_scripts() {
wp_enqueue_script('media-upload');
wp_enqueue_script('thickbox');
}
function my_admin_styles() {
wp_enqueue_style('thickb... |
203,491 | <p>I have a Wordpress blog hosted on a server without outgoing network. Therefore, Wordpress cannot check for a new version and/or update automatically to a new version.</p>
<p>Currently, the only ways I'm aware of to update the blog to a new version of WP is to follow the complicated guide <a href="https://codex.word... | [
{
"answer_id": 203492,
"author": "Mayeenul Islam",
"author_id": 22728,
"author_profile": "https://wordpress.stackexchange.com/users/22728",
"pm_score": 1,
"selected": false,
"text": "<p>I often do Manual Update, it's not that pain. :)</p>\n\n<p>Just do it in this way (I hope you know how... | 2015/09/23 | [
"https://wordpress.stackexchange.com/questions/203491",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80853/"
] | I have a Wordpress blog hosted on a server without outgoing network. Therefore, Wordpress cannot check for a new version and/or update automatically to a new version.
Currently, the only ways I'm aware of to update the blog to a new version of WP is to follow the complicated guide [here](https://codex.wordpress.org/Up... | Here's how it can be done, by temporarily making a minor fixup to the WP code:
1. Upload the zip file to the root folder of WP, in the same folder as `wp-config.php` and friends.
2. Open the file `wp-admin\includes\update.php`.
3. Find the function `find_core_update`, and change it to:
```
function find_core_update( ... |
203,495 | <p>While achieving localization of my theme, I am getting a warning:</p>
<blockquote>
<p>Warning: fopen(C:\xampp\htdocs/wp-content/themes/themename/languages): failed to open stream: Permission denied in C:\xampp\htdocs\wp-includes\pomo\streams.php on line 145 </p>
</blockquote>
<p>When I comment line for loading t... | [
{
"answer_id": 203502,
"author": "JDP",
"author_id": 57909,
"author_profile": "https://wordpress.stackexchange.com/users/57909",
"pm_score": 0,
"selected": false,
"text": "<p>I made a huge mistake by using function <code>load_textdomain</code>. While typing the code I used the auto sugge... | 2015/09/23 | [
"https://wordpress.stackexchange.com/questions/203495",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/57909/"
] | While achieving localization of my theme, I am getting a warning:
>
> Warning: fopen(C:\xampp\htdocs/wp-content/themes/themename/languages): failed to open stream: Permission denied in C:\xampp\htdocs\wp-includes\pomo\streams.php on line 145
>
>
>
When I comment line for loading text\_domain in functions.php as ... | If you want to use **load\_textdomain** you must also specify the file name:
```
function my_custom_locale()
{
load_textdomain('my-name', get_stylesheet_directory().'/languages/my-name-
'.get_locale().'.mo');
}
add_action('after_setup_theme', 'my_custom_locale');
```
In my example I added custom translation... |
203,496 | <p>I know I can edit the items within the wp_nav_menu by declaring a custom walker, but I want to add some code just inside the container, which isn't handled by a walker.</p>
<p>It's in nav-menu-menu-template.php, so I can get the desired effect by adding my code after line 329...</p>
<pre><code>$nav_menu .= "<di... | [
{
"answer_id": 203502,
"author": "JDP",
"author_id": 57909,
"author_profile": "https://wordpress.stackexchange.com/users/57909",
"pm_score": 0,
"selected": false,
"text": "<p>I made a huge mistake by using function <code>load_textdomain</code>. While typing the code I used the auto sugge... | 2015/09/23 | [
"https://wordpress.stackexchange.com/questions/203496",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/63673/"
] | I know I can edit the items within the wp\_nav\_menu by declaring a custom walker, but I want to add some code just inside the container, which isn't handled by a walker.
It's in nav-menu-menu-template.php, so I can get the desired effect by adding my code after line 329...
```
$nav_menu .= "<div class='topper'>
... | If you want to use **load\_textdomain** you must also specify the file name:
```
function my_custom_locale()
{
load_textdomain('my-name', get_stylesheet_directory().'/languages/my-name-
'.get_locale().'.mo');
}
add_action('after_setup_theme', 'my_custom_locale');
```
In my example I added custom translation... |
203,501 | <p>I am creating a wordpress website (colorsplash.info/vinovekitchenware/). Currently I am stuck with the following problem: i want to remove the white space between the header and the slider. After spending 2 to 3 hours, i am still unable to remove the space between these two section of div.</p>
<p>Here is the div se... | [
{
"answer_id": 203502,
"author": "JDP",
"author_id": 57909,
"author_profile": "https://wordpress.stackexchange.com/users/57909",
"pm_score": 0,
"selected": false,
"text": "<p>I made a huge mistake by using function <code>load_textdomain</code>. While typing the code I used the auto sugge... | 2015/09/23 | [
"https://wordpress.stackexchange.com/questions/203501",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80510/"
] | I am creating a wordpress website (colorsplash.info/vinovekitchenware/). Currently I am stuck with the following problem: i want to remove the white space between the header and the slider. After spending 2 to 3 hours, i am still unable to remove the space between these two section of div.
Here is the div section:
he... | If you want to use **load\_textdomain** you must also specify the file name:
```
function my_custom_locale()
{
load_textdomain('my-name', get_stylesheet_directory().'/languages/my-name-
'.get_locale().'.mo');
}
add_action('after_setup_theme', 'my_custom_locale');
```
In my example I added custom translation... |
203,529 | <p>I have 2 custom post types "Shops" and "Restaurants".</p>
<p>Each of these have custom fields associcated with them.</p>
<p>For example, One field in Shops is "Shop ID" and one in Restaurants is "Restaurant ID".</p>
<p>I want to query both Custom Post Types and if Shop ID is 20, I want to display all Restaurants ... | [
{
"answer_id": 203538,
"author": "Dunimas",
"author_id": 80863,
"author_profile": "https://wordpress.stackexchange.com/users/80863",
"pm_score": 0,
"selected": false,
"text": "<p>I don't know of a way to do this using WP_Query, but you can write custom SQL to achieve this:</p>\n\n<pre><c... | 2015/09/23 | [
"https://wordpress.stackexchange.com/questions/203529",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80867/"
] | I have 2 custom post types "Shops" and "Restaurants".
Each of these have custom fields associcated with them.
For example, One field in Shops is "Shop ID" and one in Restaurants is "Restaurant ID".
I want to query both Custom Post Types and if Shop ID is 20, I want to display all Restaurants with ID 20.
I've been t... | There's some contradiction between your question and the code you provided, so I'm not exactly sure which of two scenarios you're dealing with.
Scenario 1 - You want to show all Shops with a specific value for `shop-id` and all Restaurants with the same specific value for `restaurant-id`. Let's say that value is 20. Y... |
203,541 | <p>I have a very simple JS script called <code>script_1.js</code> sitting at the root level of my twentytwelve-child theme. This script contains only:</p>
<pre><code>$(document).ready(function(){console.log("scriptLoaded");
});
</code></pre>
<p>and I've loaded it with the <code>functions.php</code>:</p>
<pre><code>f... | [
{
"answer_id": 203542,
"author": "Pooja Mistry",
"author_id": 71675,
"author_profile": "https://wordpress.stackexchange.com/users/71675",
"pm_score": 1,
"selected": false,
"text": "<p>Try two things - <br>\n1. Link your js using <code>wp_enqueue_script</code> action as under : </p>\n\n<p... | 2015/09/23 | [
"https://wordpress.stackexchange.com/questions/203541",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80875/"
] | I have a very simple JS script called `script_1.js` sitting at the root level of my twentytwelve-child theme. This script contains only:
```
$(document).ready(function(){console.log("scriptLoaded");
});
```
and I've loaded it with the `functions.php`:
```
function theme_enqueue_styles() {
wp_enqueue_style( 'par... | Try two things -
1. Link your js using `wp_enqueue_script` action as under :
```
add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );
function theme_name_scripts() {
wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array('jquery'), '', true);
}
```
Third parameter in... |
203,556 | <p><strong>EDIT: Rewrote the page from scratch and have been unable to figure out the differences. The new page works as expected.</strong></p>
<p>Checked multiple questions here and also on Wordpress.org with no luck yet. Below is code I'm using in several page to take old records and plug them into the DB (with n... | [
{
"answer_id": 203586,
"author": "Dave McCourt",
"author_id": 28355,
"author_profile": "https://wordpress.stackexchange.com/users/28355",
"pm_score": 1,
"selected": false,
"text": "<p>Have you tried using manually entered data to see if that gets inserted? Just make some stuff up to repl... | 2015/09/23 | [
"https://wordpress.stackexchange.com/questions/203556",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/73022/"
] | **EDIT: Rewrote the page from scratch and have been unable to figure out the differences. The new page works as expected.**
Checked multiple questions here and also on Wordpress.org with no luck yet. Below is code I'm using in several page to take old records and plug them into the DB (with no issues on those pages). ... | I got the same problem.
**Solution 1:**
Strip your data.. Wordpress rejects the query if the length of value is greater than the field length defined on the database.
On your insert query, the value for **post\_type** field exceeded the 20 character limit.
**Solution 2:**
Use the $wpdb->query method |
203,571 | <p>I use the below code . But the code display Thumbnail in the five number column. How to move it first column position? </p>
<pre><code>//show Thumbnail in dashboard
function my_function_admin_bar(){ return false; }
add_filter( 'show_admin_bar' , 'my_function_admin_bar');
add_image_size( 'admin-list-thumb', 80, 80,... | [
{
"answer_id": 203573,
"author": "Nick",
"author_id": 65003,
"author_profile": "https://wordpress.stackexchange.com/users/65003",
"pm_score": 3,
"selected": true,
"text": "<p>You can add featured image thumbnail in post column with this code.</p>\n\n<p>Copied from here <a href=\"http://w... | 2015/09/24 | [
"https://wordpress.stackexchange.com/questions/203571",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/68406/"
] | I use the below code . But the code display Thumbnail in the five number column. How to move it first column position?
```
//show Thumbnail in dashboard
function my_function_admin_bar(){ return false; }
add_filter( 'show_admin_bar' , 'my_function_admin_bar');
add_image_size( 'admin-list-thumb', 80, 80, false );
add... | You can add featured image thumbnail in post column with this code.
Copied from here [Add Featured Post Thumbnails to WordPress Admin Post Columns](http://wpcodesnippet.com/add-featured-post-thumbnails-to-post-columns/).
Haven't tried it myself but it must work.
```
add_image_size( 'admin-list-thumb', 80, 80, false )... |
203,587 | <p>Total wordpress beginner here. I purchased a organicfood theme and when I got an updated version for it, among other files I also found organicfood child theme zip in main directory.</p>
<p>I know that organicfood.zip contains the updated version of parent theme but I don't know if same goes for organicfood child t... | [
{
"answer_id": 203573,
"author": "Nick",
"author_id": 65003,
"author_profile": "https://wordpress.stackexchange.com/users/65003",
"pm_score": 3,
"selected": true,
"text": "<p>You can add featured image thumbnail in post column with this code.</p>\n\n<p>Copied from here <a href=\"http://w... | 2015/09/24 | [
"https://wordpress.stackexchange.com/questions/203587",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80902/"
] | Total wordpress beginner here. I purchased a organicfood theme and when I got an updated version for it, among other files I also found organicfood child theme zip in main directory.
I know that organicfood.zip contains the updated version of parent theme but I don't know if same goes for organicfood child theme zip. ... | You can add featured image thumbnail in post column with this code.
Copied from here [Add Featured Post Thumbnails to WordPress Admin Post Columns](http://wpcodesnippet.com/add-featured-post-thumbnails-to-post-columns/).
Haven't tried it myself but it must work.
```
add_image_size( 'admin-list-thumb', 80, 80, false )... |
203,599 | <p>Plugin in question: <a href="http://dimsemenov.com/plugins/royal-slider/wordpress/" rel="nofollow">http://dimsemenov.com/plugins/royal-slider/wordpress/</a></p>
<p>Background: This is a great plugin, and it features a 'post' version where the slider pulls content from posts. However, the taxonomy for the posts that... | [
{
"answer_id": 203597,
"author": "Aravona",
"author_id": 49852,
"author_profile": "https://wordpress.stackexchange.com/users/49852",
"pm_score": 2,
"selected": true,
"text": "<blockquote>\n <p>If someone has managed to access the admin area by making it look like they are someone else, ... | 2015/09/24 | [
"https://wordpress.stackexchange.com/questions/203599",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/47880/"
] | Plugin in question: <http://dimsemenov.com/plugins/royal-slider/wordpress/>
Background: This is a great plugin, and it features a 'post' version where the slider pulls content from posts. However, the taxonomy for the posts that it's pulling has to be set at the slider settings level in WordPress, it can't be done via... | >
> If someone has managed to access the admin area by making it look like they are someone else, isn't it all over anyway?
>
>
>
This to me is more part of your exclusions as this is the main way anyone gains access through WordPress... So not really, if you have a backup, just drop the Database, upload your back... |
203,618 | <p>I need to add new sidebars for using them accordingly on different pages throughout my shop.</p>
<p>I use Woocommerce and my own Storefront child theme.</p>
<p>This is a snippet of what is in functions.php file of the child theme.</p>
<pre><code>add_action( 'init', 'init_storefront_child' );
function init_storef... | [
{
"answer_id": 203597,
"author": "Aravona",
"author_id": 49852,
"author_profile": "https://wordpress.stackexchange.com/users/49852",
"pm_score": 2,
"selected": true,
"text": "<blockquote>\n <p>If someone has managed to access the admin area by making it look like they are someone else, ... | 2015/09/24 | [
"https://wordpress.stackexchange.com/questions/203618",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/73239/"
] | I need to add new sidebars for using them accordingly on different pages throughout my shop.
I use Woocommerce and my own Storefront child theme.
This is a snippet of what is in functions.php file of the child theme.
```
add_action( 'init', 'init_storefront_child' );
function init_storefront_child() {
// It se... | >
> If someone has managed to access the admin area by making it look like they are someone else, isn't it all over anyway?
>
>
>
This to me is more part of your exclusions as this is the main way anyone gains access through WordPress... So not really, if you have a backup, just drop the Database, upload your back... |
203,623 | <p>Wordpress nav menu created by wp_nav_menu can highlight current menu item. How can i strip anchor from current menu item?</p>
<p>For example, we have menu:</p>
<pre><code><ul>
<li class="current-menu-item"><a href="/somelink">Home</a></li>
<li><a href="/elselink">Item<... | [
{
"answer_id": 203597,
"author": "Aravona",
"author_id": 49852,
"author_profile": "https://wordpress.stackexchange.com/users/49852",
"pm_score": 2,
"selected": true,
"text": "<blockquote>\n <p>If someone has managed to access the admin area by making it look like they are someone else, ... | 2015/09/24 | [
"https://wordpress.stackexchange.com/questions/203623",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80919/"
] | Wordpress nav menu created by wp\_nav\_menu can highlight current menu item. How can i strip anchor from current menu item?
For example, we have menu:
```
<ul>
<li class="current-menu-item"><a href="/somelink">Home</a></li>
<li><a href="/elselink">Item</a></li>
...
</ul>
```
Can we remove
```
<a href="/somelink... | >
> If someone has managed to access the admin area by making it look like they are someone else, isn't it all over anyway?
>
>
>
This to me is more part of your exclusions as this is the main way anyone gains access through WordPress... So not really, if you have a backup, just drop the Database, upload your back... |
203,628 | <p>I have a widget I want only allowed to be used with the single.php sidebar. When I referenced the codex for <a href="https://codex.wordpress.org/Function_Reference/register_sidebar" rel="nofollow noreferrer"><code>register sidebar</code></a> there isn't a way to limit widgets in the array. I've researched with "Wo... | [
{
"answer_id": 204107,
"author": "Pieter Goosen",
"author_id": 31545,
"author_profile": "https://wordpress.stackexchange.com/users/31545",
"pm_score": 3,
"selected": true,
"text": "<p>My jquery knowledge is still almost non existent, so I'm not sure if <a href=\"https://www.quora.com/Wor... | 2015/09/24 | [
"https://wordpress.stackexchange.com/questions/203628",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/25271/"
] | I have a widget I want only allowed to be used with the single.php sidebar. When I referenced the codex for [`register sidebar`](https://codex.wordpress.org/Function_Reference/register_sidebar) there isn't a way to limit widgets in the array. I've researched with "WordPress limit widget to post" but they are only plugi... | My jquery knowledge is still almost non existent, so I'm not sure if [the solution](https://www.quora.com/WordPress-Theme-Development/Is-there-a-way-to-trigger-a-JavaScript-function-when-a-particular-widget-is-drag-and-dropped-in-widgets-php-of-the-admin-area) works that was suggested by @Howdy\_McGee in comments.
An... |
203,639 | <p>How do I get total number of Authors on the site?</p>
<p>This shows summery of users on the site but I just want to get number of Authors.</p>
<pre><code><?php
$result = count_users();
echo 'There are ', $result['total_users'], ' total users';
foreach($result['avail_roles'] as $role => $count)
echo ', ',... | [
{
"answer_id": 203643,
"author": "bueltge",
"author_id": 170,
"author_profile": "https://wordpress.stackexchange.com/users/170",
"pm_score": 2,
"selected": false,
"text": "<p>You can use the <a href=\"https://codex.wordpress.org/Class_Reference/WP_User_Query\" rel=\"nofollow\"><code>WP_U... | 2015/09/24 | [
"https://wordpress.stackexchange.com/questions/203639",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/74171/"
] | How do I get total number of Authors on the site?
This shows summery of users on the site but I just want to get number of Authors.
```
<?php
$result = count_users();
echo 'There are ', $result['total_users'], ' total users';
foreach($result['avail_roles'] as $role => $count)
echo ', ', $count, ' are ', $role, 's... | You can use the [`WP_User_Query`](https://codex.wordpress.org/Class_Reference/WP_User_Query) class, like the example below. Each code line have an small description, that you understand, what we do.
```
// Get all users with role Author.
$user_query = new WP_User_Query( array( 'role' => 'Author' ) );
// Get the total ... |
203,656 | <p>Sorry for this question, but I can't work out why my site name isn't showing in the browser window even though I have <code>wp_title()</code> in the <code><head></code>. </p>
<p>All I have done is used CSS to indent the text -9999px so it's off the screen but I thought that would still register as the title i... | [
{
"answer_id": 203643,
"author": "bueltge",
"author_id": 170,
"author_profile": "https://wordpress.stackexchange.com/users/170",
"pm_score": 2,
"selected": false,
"text": "<p>You can use the <a href=\"https://codex.wordpress.org/Class_Reference/WP_User_Query\" rel=\"nofollow\"><code>WP_U... | 2015/09/24 | [
"https://wordpress.stackexchange.com/questions/203656",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/66157/"
] | Sorry for this question, but I can't work out why my site name isn't showing in the browser window even though I have `wp_title()` in the `<head>`.
All I have done is used CSS to indent the text -9999px so it's off the screen but I thought that would still register as the title in the browser?
When I navigate throug... | You can use the [`WP_User_Query`](https://codex.wordpress.org/Class_Reference/WP_User_Query) class, like the example below. Each code line have an small description, that you understand, what we do.
```
// Get all users with role Author.
$user_query = new WP_User_Query( array( 'role' => 'Author' ) );
// Get the total ... |
203,670 | <p>I am working on <a href="http://www.kensingtonmn.com/wordpress/churches-and-schools/" rel="nofollow">this WP website</a> and can't for the life of me get the entire height of the sidebar to take the background setting.</p>
<p>The theme is a child of TwentyFourteen. Through FireFox's Inspect Element I can see my bac... | [
{
"answer_id": 203643,
"author": "bueltge",
"author_id": 170,
"author_profile": "https://wordpress.stackexchange.com/users/170",
"pm_score": 2,
"selected": false,
"text": "<p>You can use the <a href=\"https://codex.wordpress.org/Class_Reference/WP_User_Query\" rel=\"nofollow\"><code>WP_U... | 2015/09/25 | [
"https://wordpress.stackexchange.com/questions/203670",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/73969/"
] | I am working on [this WP website](http://www.kensingtonmn.com/wordpress/churches-and-schools/) and can't for the life of me get the entire height of the sidebar to take the background setting.
The theme is a child of TwentyFourteen. Through FireFox's Inspect Element I can see my background-color setting on the #second... | You can use the [`WP_User_Query`](https://codex.wordpress.org/Class_Reference/WP_User_Query) class, like the example below. Each code line have an small description, that you understand, what we do.
```
// Get all users with role Author.
$user_query = new WP_User_Query( array( 'role' => 'Author' ) );
// Get the total ... |
203,678 | <p>I'm building a theme that generates on the home template a link to the PDF attached to the post (it will be only PDF files).</p>
<p>I found a solution to check if the post has a PDF attached. The goal is to create a link that downloads the file, on the home (blog) template.</p>
<p>Here's what I currently have</p>
... | [
{
"answer_id": 203683,
"author": "Krzysiek Dróżdż",
"author_id": 34172,
"author_profile": "https://wordpress.stackexchange.com/users/34172",
"pm_score": 3,
"selected": false,
"text": "<p>Well, there is a WP function for that.</p>\n\n<p>wp_get_attachment_url</p>\n\n<p>It takes attachment ... | 2015/09/25 | [
"https://wordpress.stackexchange.com/questions/203678",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/43151/"
] | I'm building a theme that generates on the home template a link to the PDF attached to the post (it will be only PDF files).
I found a solution to check if the post has a PDF attached. The goal is to create a link that downloads the file, on the home (blog) template.
Here's what I currently have
```
function leoni_g... | Well, there is a WP function for that.
wp\_get\_attachment\_url
It takes attachment id as argument, so you can use it like in following example:
```
echo wp_get_attachment_url( 12 );
```
This will echo url to attachment which id is 12.
You can find more info and examples on Codex page:
<https://codex.wordpress.or... |
203,715 | <p>I'm a bit confused with templates for custom post types defined as hierarchical. I've got a CPT set to hierarchical, not strictly in order to have a nested hierarchy, but so that they can be ordered by the Simple Page Ordering plugin. Here's the code:</p>
<pre><code>register_post_type(
'case_study', array(
... | [
{
"answer_id": 203852,
"author": "Steve Taylor",
"author_id": 2336,
"author_profile": "https://wordpress.stackexchange.com/users/2336",
"pm_score": 0,
"selected": false,
"text": "<p>I sense I'm still missing something, but for now I've approached this another way. Since the only reason f... | 2015/09/25 | [
"https://wordpress.stackexchange.com/questions/203715",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/2336/"
] | I'm a bit confused with templates for custom post types defined as hierarchical. I've got a CPT set to hierarchical, not strictly in order to have a nested hierarchy, but so that they can be ordered by the Simple Page Ordering plugin. Here's the code:
```
register_post_type(
'case_study', array(
'label' ... | Old question but maybe it helps someone else:
You could do something like this in page.php:
```
$postType = get_post_type();
if($postType == 'case_study'){
include('single-case_study.php');
} else{
// Do your page.php stuff
``` |
203,717 | <p><a href="https://i.stack.imgur.com/XT3hX.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XT3hX.jpg" alt="enter image description here"></a></p>
<p>Hi. I don't know ajax programming. I know HTML, CSS, little bit of php(so much that I am editing and customizing all the default themes, and learning ... | [
{
"answer_id": 203852,
"author": "Steve Taylor",
"author_id": 2336,
"author_profile": "https://wordpress.stackexchange.com/users/2336",
"pm_score": 0,
"selected": false,
"text": "<p>I sense I'm still missing something, but for now I've approached this another way. Since the only reason f... | 2015/09/25 | [
"https://wordpress.stackexchange.com/questions/203717",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/80956/"
] | [](https://i.stack.imgur.com/XT3hX.jpg)
Hi. I don't know ajax programming. I know HTML, CSS, little bit of php(so much that I am editing and customizing all the default themes, and learning along the way).
I have attached the UI of the page which my... | Old question but maybe it helps someone else:
You could do something like this in page.php:
```
$postType = get_post_type();
if($postType == 'case_study'){
include('single-case_study.php');
} else{
// Do your page.php stuff
``` |
203,750 | <p>guys! I'm pretty sure this will be a piece of cake for y`all, but I'm trying to add pagination to my loop. I've tried some codes that were available around, and got to paginate it, but pages 2, 3, etc had the same content from page 1. What's the best solution for what I have at the moment?</p>
<pre><code><?php
... | [
{
"answer_id": 203759,
"author": "shanebp",
"author_id": 16575,
"author_profile": "https://wordpress.stackexchange.com/users/16575",
"pm_score": 0,
"selected": false,
"text": "<p>There are few ways to do <a href=\"https://codex.wordpress.org/Pagination\" rel=\"nofollow\">pagination</a>. ... | 2015/09/25 | [
"https://wordpress.stackexchange.com/questions/203750",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/78848/"
] | guys! I'm pretty sure this will be a piece of cake for y`all, but I'm trying to add pagination to my loop. I've tried some codes that were available around, and got to paginate it, but pages 2, 3, etc had the same content from page 1. What's the best solution for what I have at the moment?
```
<?php
$recentPosts =... | Likely this is happening because you are using a custom page template. Try the following. I've commented the steps along the way. Hope it helps.
```
<?php
//get the current page
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
//pagination fixes prior to loop
$temp = $query;
$query = null;
... |
203,787 | <p>I am trying to add the current post's author as the content for the meta author tag. I wrapped this particular meta in an <code>is_single</code> condition and then tried:</p>
<pre><code><meta name="author" content="<?php get_the_author(); ?>" />
</code></pre>
<p>as well as tried this... | [
{
"answer_id": 203826,
"author": "coopersita",
"author_id": 21258,
"author_profile": "https://wordpress.stackexchange.com/users/21258",
"pm_score": 2,
"selected": false,
"text": "<p>You cad add it via <code>functions.php</code> with a hook, instead of inside the loop (you don't really wa... | 2015/09/26 | [
"https://wordpress.stackexchange.com/questions/203787",
"https://wordpress.stackexchange.com",
"https://wordpress.stackexchange.com/users/74607/"
] | I am trying to add the current post's author as the content for the meta author tag. I wrapped this particular meta in an `is_single` condition and then tried:
```
<meta name="author" content="<?php get_the_author(); ?>" />
```
as well as tried this:
```
<meta name="author" content="<?php the_author(); ?>" />
```
... | You cad add it via `functions.php` with a hook, instead of inside the loop (you don't really want to add a loop to header.php):
```
function add_author_meta() {
if (is_single()){
global $post;
$author = get_the_author_meta('user_nicename', $post->post_author);
echo "<meta name=\"author\" c... |