• I am trying to do a custom query and it works fine using:
    $query= 'tag=' . $value. '&showposts=1&random=true';

    My only concern is I also want to say where tag = a string, but also that post doesn’t contain some other tags.

    For example if I have 2 posts, one with tags = design, poster, happy. Then another post with the tags = design, art, nsfw. I would like to have a way to say, if the post has the tag ‘nsfw‘ skip this item in the query result.

    Any ideas?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter ywftdg

    (@ywftdg)

    I have even tryed using a custom query, and the mysql LIKE feature does not work.

    $querystr = "
    				SELECT wposts.*
    				FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
    				WHERE wposts.ID = wpostmeta.post_id
    				AND wpostmeta.meta_key = 'tag'
    				AND wpostmeta.meta_value LIKE 'art%'
    				AND wposts.post_status = 'publish'
    				AND wposts.post_type = 'post'
    				ORDER BY wposts.post_date DESC
     			";

    What is the deal with LIKE not working?

    Thread Starter ywftdg

    (@ywftdg)

    Bump: nobody out there ever had to query wordpress database using LIKE?

    i dont know too much about this stuff, i just started querying the worpress db, but i copied you query to test and i needed to change the table name to “wp_posts” and “wp_postmeta”

    Fairly simple… This should do the trick.

    "SELECT " . $wpdb->prefix . "posts.* FROM " . $wpdb->prefix . "posts JOIN " . $wpdb->prefix . "term_relationships ON " . $wpdb->prefix . "posts.id = " . $wpdb->prefix . "term_relationships.object_id LEFT JOIN " . $wpdb->prefix . "terms ON " . $wpdb->prefix . "term_relationships.term_taxonomy_id = " . $wpdb->prefix . "terms.term_id WHERE " . $wpdb->prefix . "terms.name != 'nsfw' AND " . $wpdb->prefix . "terms.name = 'art' AND " . $wpdb->prefix . "posts.post_status = 'publish' AND " . $wpdb->prefix . "posts.post_type = 'post' GROUP BY " . $wpdb->prefix . "posts.id"

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom Query Tag = and Tag !=’ is closed to new replies.