Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

List posts from specific tags WordPress


This question goes regarding a calendar [[LINK href=""]]tutorial of this page[[/LINK]]:

I'm trying to list calendar posts from a specific tag on a regular frontage (index.php or frontage.php) in this tutorial with no luck. Let's say it should list posts only with the tags of towns like "boston" and "newyork" . I figure there must be a code that starts with something like AND +boston AND + newyork(or their ID, it doesn't matter just as long it lists the posts of the tags)... after the row in the section with:

$querystr = "
SELECT wposts.*
FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
WHERE wposts.ID = wpostmeta.post_id";


* Do we need to filter by event tag?
if(is_tax('event_tags') ) :
$tag = strip_tags( get_query_var('event_tags') );

$querystr = "
SELECT wposts.*
FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta, $wpdb->terms wterms, $wpdb->term_taxonomy wtax, $wpdb->term_relationships wrels
WHERE wposts.ID = wpostmeta.post_id
AND wterms.term_id = wtax.term_id
AND wtax.term_taxonomy_id = wrels.term_taxonomy_id
AND wrels.object_id = wposts.ID
AND wterms.slug = '$tag'

$querystr = "
SELECT wposts.*
FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
WHERE wposts.ID = wpostmeta.post_id";

// Build the rest of the query, i.e. only get events with dates, and order newest first.
$querystr .= "
AND wpostmeta.meta_key = 'Date'
AND STR_TO_DATE(wpostmeta.meta_value,'%m/%d/%Y') >= CURDATE()
AND wposts.post_status = 'publish'
AND wposts.post_type = 'events'
ORDER BY STR_TO_DATE(wpostmeta.meta_value,'%m/%d/%Y') ASC

Answers (4)


Hai Bui answers:

With the code from that tutorial, you can only get the posts for only one town. And it's weird they are not using WQ_Query or query posts.
In order to help you, please let us know how the url looks like, is it like this?

hlx5 comments:

It's fine if it is just from one town.
The thought is that the list is only going to show posts with the tag "boston" on the frontpage. With the current code all towns show up.