• Hi, im looking to pull 3 posts from a specific WordPress Category. At the minute I can pull 3 latest posts and display them in a flash banner using the code below.

    SELECT yah_posts.*, yah_postmeta.*
    FROM yah_posts
    LEFT JOIN yah_postmeta ON yah_posts.ID = yah_postmeta.post_id
    WHERE yah_postmeta.meta_key = 'largeimage' && yah_posts.post_status = 'publish'
    ORDER BY post_date DESC LIMIT 3

    I want to be able to pull 3 latest posts from a specific category instead of just 3 latest posts from every category.

    I have put together this code below, but it doesn’t seem to be working ??

    $query = "SELECT yah_posts.*, yah_postmeta.*
    FROM yah_posts
    LEFT JOIN yah_postmeta ON yah_posts.ID = yah_postmeta.post_id
    AND LEFT JOIN $yah_term_taxonomy ON($yah_term_relationships.term_taxonomy_id = $yah_term_taxonomy.term_taxonomy_id)
    WHERE yah_postmeta.meta_key = 'largeimage' && yah_posts.post_status = 'publish'
    AND $yah_term_taxonomy.term_id = '1'
    AND $yah_term_taxonomy.taxonomy = 'category'
    ORDER BY post_date DESC LIMIT 3";
Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi, will something like this work for you?

    $args = array( 'category_name' => 'your_category', 'numberposts' => '3', 'order'=> 'ASC' );
    $postslist = get_posts( $args );
    foreach ($postslist as $post) :  setup_postdata($post); ?> 
    
    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    <?php the_excerpt(); ?>
    
    <?php endforeach; ?>
    Thread Starter mccrum

    (@mccrum)

    Hi, im pulling data into an XML file which is then being displayed though a Flash Banner.

    The first set of code above is working and pulling 3 latest posts but I need 3 latest posts from a specific category.

    Unfortunately thats a bit beyond what I know about MYSQL queries.

    Have you tried adding another WHERE or AND clause thats category specific?

    Sorry, you may need to wait for someone a bit better than me to come along on this one ; )

    Dan

    Thread Starter mccrum

    (@mccrum)

    Thanks for your help anyway ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Pull post from a specific WordPress category’ is closed to new replies.