开发者

wordpress filter by slugs

开发者 https://www.devze.com 2023-03-16 06:41 出处:网络
开发者_Python百科i\'m trying to make a filter in wordpress. I want the selecect to find all posts with selected tag slugs.

开发者_Python百科i'm trying to make a filter in wordpress.

I want the selecect to find all posts with selected tag slugs.

$vare_array is "tagshopconverse,tagcategorysko,tagbrandconverse"

this select is working with " OR " - its finding all posts with the tags, but not with " AND " and i need them to be inclusive - all tags must be in posts.

$slugs = "";
$andor = " AND ";
foreach( $vare_array as $vare ) {
    $slugs = $slugs . $andor ."$wpdb->terms.slug = '".$vare."'";
    $andor = " OR ";
}

$postids = $wpdb->get_col($wpdb->prepare("
    SELECT * 
    FROM $wpdb->posts
    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)
    LEFT JOIN $wpdb->terms ON($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id)
    WHERE $wpdb->posts.post_type = 'post' 
    AND $wpdb->posts.post_status = 'publish'
    {$slugs}
"));

/thanks


If you are using a latest WordPress, you can use taxonomy queries, see this topic: http://wordpress.org/support/topic/tax_query-and-wp_query-how-to?replies=4

0

精彩评论

暂无评论...
验证码 换一张
取 消