Posts in loop all show the same author when there are many authors

You need to move the bulk of your code into the loop proper. This part: $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); $ids[]= $post->ID; endwhile; } When the_post() executes, it populates the $post global upon which a number of template functions depend. The problem is that you are running your … Read more

Highlight current post title on a page

That’s easy: You should use $wp_query->current_post to retrieve the index of your custom query. In your case query will work something like this: <ul class=”post-list”> <?php $query = new WP_Query( array( ‘post_type’ => ‘campaign-post’ ) ); while ( $query->have_posts() ) : $query->the_post(); if($query->current_post == 0){ ?> <h1 class=”current”><?php the_title(); ?></h1> <?php } else{ ?> <h1 … Read more

Wildcard search in WP Query

WP_Query will add the % wildcard operators for a LIKE query. Just remove those. As is your query looks like LIKE ‘%\\%rocket\\%% which is not what you want. Try var_dump($query->request); And you can see that for yourself.

filter wp_query result with custom field values

If main_category is a category (custom taxonomy), then you’re querying it wrong. This should go like this: $electronics = array( ‘numberposts’ => -1, ‘post_type’ => ‘article’, ‘main_category’ => ‘electronics’ ); $query_electronics = new WP_Query( $electronics ); If that’s a custom field, use meta_query: $electronics = array( ‘numberposts’ => -1, ‘post_type’ => ‘article’, ‘meta_query’ => array( … Read more