Constructing a WP_Query (6 posts)

  1. Maraki
    Posted 3 years ago #

    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!

  2. Justin
    Posted 3 years ago #

    Something like the following ( may not be completely accurate ). For the thumbnail you could run get_post_meta() or better. Visit http://codex.wordpress.org/Post_Thumbnails for documentation for thumbnails

    $args = array(
    	'post_type' => 'os_calendar',
    	'taxonomy' => 'formula1',
            'post_per_page' => 5
    $query = new WP_Query( $args );
  3. Maraki
    Posted 3 years ago #

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

  4. Maraki
    Posted 3 years ago #

    $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 :(

  5. racer x
    Posted 3 years ago #

    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.

  6. Maraki
    Posted 3 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.