• Hi,

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

    <?php
    $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.

    thanks

Viewing 1 replies (of 1 total)
  • Thread Starter bobdeo

    (@bobdeo)

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

    <?php
    $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);
    ?>

Viewing 1 replies (of 1 total)

The topic ‘Custom select query’ is closed to new replies.