Forums

[resolved] Showing posts side by side (3 posts)

  1. dsohigian
    Member
    Posted 2 years ago #

    I am trying to set up a wordpress site that will show two posts side by side as a "point/counterpoint". The main page was easy:

    http://xsaidysaid.sohigian.com

    I simply used categories to position the latest post on each side of the page.

    But I want single post pages to also show up with the two articles with the same topic to be paired together. My first thought was to use meta key values, but I am having difficulty with the query used to make them show up in 2.7. I will describe further, but I am wondering if there is another approach that would make more sense as well.

    My query code looks like this:

    <?php
    
     $querystr = "
    SELECT * FROM $wpdb->posts
    LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
    LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
    LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    WHERE $wpdb->term_taxonomy.term_id = 114
    AND $wpdb->term_taxonomy.taxonomy = 'category'
    AND $wpdb->posts.post_status = 'publish'
    AND $wpdb->postmeta.meta_key = 'Topic'
     ";
     $pageposts = $wpdb->get_results($querystr, OBJECT);
    ?>

    I am looking for all the posts in category 114 which have a meta_key of Topic. Eventually I also want to get the value of that meta key, but I can't even get this to return any results.

    Again I am open to other suggestions for approaches.

  2. MichaelH
    Volunteer
    Posted 2 years ago #

    The template tag, query_posts(), or a new WP_Query(), will do that:

    query_posts('meta_key=Topic&cat=114');

    Related:
    http://weblogtoolscollection.com/archives/2008/04/13/define-your-own-wordpress-loop-using-wp_query/

  3. dsohigian
    Member
    Posted 2 years ago #

    @MichaelH - thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags