Title: Custom select query
Last modified: August 18, 2016

---

# Custom select query

 *  [bobdeo](https://wordpress.org/support/users/bobdeo/)
 * (@bobdeo)
 * [19 years, 6 months ago](https://wordpress.org/support/topic/custom-select-query/)
 * 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.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query](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 :
 * ` <?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](https://wordpress.org/support/users/bobdeo/)
 * (@bobdeo)
 * [19 years, 6 months ago](https://wordpress.org/support/topic/custom-select-query/#post-483240)
 * 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.

## Tags

 * [query](https://wordpress.org/support/topic-tag/query/)
 * [select](https://wordpress.org/support/topic-tag/select/)
 * [tag](https://wordpress.org/support/topic-tag/tag/)
 * [UTW](https://wordpress.org/support/topic-tag/utw/)

 * 1 reply
 * 1 participant
 * Last reply from: [bobdeo](https://wordpress.org/support/users/bobdeo/)
 * Last activity: [19 years, 6 months ago](https://wordpress.org/support/topic/custom-select-query/#post-483240)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
