solutionweb

WordPress Common Errors and Solutions

WordPress uses ignore_sticky_posts instead of caller_get_posts.

When query_posts is used to output the ranking of top articles on the home page, the latest top articles will appear and need to be excluded. However, after opening wordpress debugging mode, it is found that WP gives the following tips:

Notice: Since version 3.1.0, it is no longer recommended to pass in a parameter to WP_Query! “caller_get_posts” is no longer recommended. Please use “ignore_sticky_posts” instead. in XXXX\XXXX\wp-includes\functions.php on line 3891

Ignore_sticky_posts means whether to display the latest top articles on the list controlled by query_posts. The default value is 0, and top articles are not excluded. Please note that ignore/exclude sticky posts being included at the beginning of posts returned, But the sticky post will still be returned in the natural order of that list of posts.

Examples of usage
Show (return) only the first top article:

$sticky = get_option( ‘sticky_posts’ );
$query = new WP_Query( ‘p=’ . $sticky[0] );
Return to the first top article, otherwise the latest published article will be displayed:

$args = array(
‘posts_per_page’ => 1,
‘post__in’ => get_option( ‘sticky_posts’ ),
‘ignore_sticky_posts’ => 1
);
$query = new WP_Query( $args );
Exclude all top articles in the query:

$query = new WP_Query( array( ‘post__not_in’ => get_option( ‘sticky_posts’ ) ) );
Returns all articles under a certain category, and does not display the top articles in the article list. But its top articles are still displayed in other natural sorting, such as date sorting archive:

$query = new WP_Query( array( ‘ignore_sticky_posts’ => 1, ‘posts_per_page’ => 3, ‘cat’ => 6 );

Back to top