Ready to get started?Download WordPress


Custom select query (2 posts)

  1. bobdeo
    Posted 7 years ago #


    I try to use a custom select query to display all the posts of a UTW tag (Tag id = 546).
    The page http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query is very clear but I fail to make the first query to replace this :

    $pageposts = $wpdb->get_results("SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
    WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = 'tag' AND wpostmeta.meta_value = 'email' AND
    wposts.post_status = 'publish' AND wposts.post_date < NOW() ORDER BY wposts.post_date DESC", OBJECT);

    This query displays all the post id linked with the tag 546 :
    SELECT 'post_id' FROM 'wp_post2tag' WHERE 'tag_id' = 546

    If it's easy for you, please help me.


  2. bobdeo
    Posted 7 years ago #

    ok... so I try with this and it works... but it don't think it's very clean...

    $pageposts = $wpdb->get_results("
    SELECT wp_posts.* FROM wp_posts, wp_post2tag WHERE wp_posts.ID = wp_post2tag.post_id AND wp_post2tag.tag_id = 546 AND wp_posts.post_status = 'publish' AND wp_posts.post_date < NOW() ORDER BY wp_posts.post_date DESC LIMIT 0,3", OBJECT);

Topic Closed

This topic has been closed to new replies.

About this Topic