Support » Fixing WordPress » Constructing a WP_Query

  • Hi there,

    I am a newbie when it comes to coding and I want to construct a WP_Query based on the codex.

    The arguments are:

    – 5 posts
    – from custom post type “os_calendar”
    – in taxonomy called “formula1”
    – showing the thumbnail (preferably my defined custom thumbnail size called “spotlight”) & post title in a list .li. format

    Your help is much appreciated!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Something like the following ( may not be completely accurate ). For the thumbnail you could run get_post_meta() or better. Visit for documentation for thumbnails

    $args = array(
    	'post_type' => 'os_calendar',
    	'taxonomy' => 'formula1',
            'post_per_page' => 5
    $query = new WP_Query( $args );

    ok that looks good but i probably need some more help as i am getting confused with the image placement!

    $args = array(
    'post_type' => 'os_calendar',
    'taxonomy' => 'calendar_event_type',
    'post_per_page' => 5);
    $recentPosts = new WP_Query( $args );
    while ($recentPosts->have_posts()) : $recentPosts->the_post();
    <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
    <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    <?php endwhile; ?>
    <?php wp_reset_query(); ?>

    I came up with the above to start with but for some reason i am getting blank results 🙁

    You don’t need this line at all:
    You have already limited the posts to 5 in the args.

    You may want to look at the taxonomy section again in the codex. Are you looking for a specific term from that taxonomy?

    To get the post thumbnail at your custom size:
    <?php echo get_the_post_thumbnail( $post->ID, 'spotlight' ); ?>

    Hope that helps a little.

    Yes it does.. I also got this reply from my theme editor which i think messes up my code..

    Yes, the pre_get_posts filter that is used in functions/custom.php lines 23 – 40 alters the query. You should add suppress_filters to your query.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Constructing a WP_Query’ is closed to new replies.