Adding ‘current_post_item’ class to current post in the loop

You should be able to get the queried object id and use that for comparison inside your custom loop.. Before your existing loop code(what you have posted above), but obviously after the opening PHP tag.. global $wp_query; $current_id = $wp_query->get_queried_object_id(); Then somewhere inside your custom WP loops.. if( $current_id == get_the_ID() ) { // This … Read more

Show two random posts from custom post type

You need an orderby argument. $args = array( ‘post_type’ => ‘custom_advert’, ‘posts_per_page’ => 2, ‘orderby’ => ‘rand’ ); That should pull posts in a random order and stop after retrieving the first two, hence two random posts.

the_content and wp_link_pages

I guess you have: the_content(); wp_link_pages(); in your theme file. So you can instead try the following (PHP 5.4+): /** * Append the wp_link_pages to the content. */ ! is_admin() && add_filter( ‘the_content’, function( $content ) { if( in_the_loop() ) { $args = [ ‘echo’ => false ]; // <– Adjust the arguments to your … Read more

Are there any scenarios where the query_posts may be used?

query_posts() is useful in cases when there is no main query: calls to wp-admin/admin-ajax.php, wp-admin/admin-post.php or wp-login.php for example. Yes, you can achieve the same results there without query_posts() and slightly less compact code instead. But if you don’t have to care about side effects, using query_posts() is acceptable.

Is `query_posts` really slower than secondary query?

You ask: is query_posts really slower than some secondary query… The fact is that if you’re calling query_posts() from a theme then it already is a secondary query. WordPress has already queried the database once to get a certain page then it hits your query_posts() function and queries the database again creating a second query … Read more