pass parameters through variable to WP_QUERY

You are wrapping your parameters string in unnecessary layer of quotes: $parameters = “‘category__in=1′”; — wrong $parameters=”category__in=1″; — right It is usually preferable to use arrays for query arguments: $parameters = [ ‘category__in’ => 1 ];

Force WordPress to be more random

I wanted to point out that sometimes in the case of random it’s not the code at all, if you’re using a host that does auto cache or are using a cache plugin, it’s possible the page or the query itself is getting cached and therefor the same results will show. Fixes for this issue … Read more

wp_query get attachments in larger size

If you look at the raw post data… while (have_posts() ) { the_post(); ?> <article id=”post-<?php the_ID(); ?>” <?php post_class(); ?>><?php var_dump($post); ?> </article><?php } You will see that there is nothing in there to specify “medium”, so I went looking. There is a filter on the_content… add_filter( ‘the_content’, ‘prepend_attachment’ ); … that juggles data … Read more

Pagination for custom loop on custom page template is not displaying anything

Harman, don’t use get_posts() when pagination is required. You may also accomplish this task using WP_Query. Refer to this answer explained beautifully by Chip Bennett at How to fix pagination for custom loops? <?php $user_fav = get_user_favorites($user_id); $paged = ( get_query_var( ‘paged’ ) ) ? get_query_var( ‘paged’ ) : 1; $args = array( ‘posts_per_page’ => … Read more

is_404() – where does this get set?

There is a dedicated method for it WP_Query->set_404(). From quick search through code it can be set in WP_Query->parse_query() or WP->handle_404() (note WP, not WP_Query!). But it can (and sometimes does) get set on query externally, for example by plugin that needs to invalidate specific resource.