SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2013
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool Construct Complex WP_Query

    Hello,

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

    https://codex.wordpress.org/Class_Reference/WP_Query

    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!

    Many thanks,
    Andy

  2. #2
    SitePoint Enthusiast
    Join Date
    Feb 2013
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am currently using

    Code:
    <?php
    
    $args = array(
    'post_type' => 'os_calendar',
    'taxonomy' => 'calendar_event_type',
    'post_per_page' => 5);
    $recentPosts = new WP_Query( $args );
    $recentPosts->query('showposts=5');
    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>
     
    </div>
    
    <?php endwhile; ?>
    <?php wp_reset_query(); ?>
    but nothing is returned.. i must be doing sth wrong somewhere..

  3. #3
    Barefoot on the Moon! silver trophy
    Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,516
    Mentioned
    51 Post(s)
    Tagged
    1 Thread(s)
    Check your taxonomy. It differs between what you originally posted and what's in your code.

    Also:

    Code:
    $recentPosts = new WP_Query( $args );
    $recentPosts->query('showposts=5');
    The second statement is unnecessary. The posts_per_page argument takes care of this.
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2013
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i think my theme is to be blamed.. Here is what the author said:

    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •