• I’m running a couple of custom queries on custom post templates, and can’t figure out how to exclude a specific category from results.

    In my database, in the wordpress_posts table, all the “post_category” fields are 0. However, the posts are in their own categories, and working right. So I’m not sure where the category gets saved.

    I’m using this query:

    $querystr = "
        SELECT DISTINCT wordpress_posts.*
        FROM $wpdb->posts wordpress_posts
        WHERE wordpress_posts.post_content LIKE '%$first_name $last_name%'
        AND wordpress_posts.post_status = 'publish'
        AND wordpress_posts.post_type = 'post'
        ORDER BY wordpress_posts.post_date DESC

    I’m defining first_name and last_name from custom fields in WordPress.

    I’ve tried:

    $querystr = "
        SELECT DISTINCT wordpress_posts.*
        FROM $wpdb->posts wordpress_posts
        WHERE wordpress_posts.post_content LIKE '%$first_name $last_name%'
        AND wordpress_posts.post_category != '1302'
        AND wordpress_posts.post_status = 'publish'
        AND wordpress_posts.post_type = 'post'
        ORDER BY wordpress_posts.post_date DESC

    But that didn’t work. Can someone point me in the right direction? (which, with my luck, is right in front of my face)

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

    (@mikejandreau)

    I tried a bunch of other things, and I can’t seem to figure out where the post_category data is stored now. It’s definitely not in the _posts table anymore. (those are all 0s now)

    Anyone lend a hand?

Viewing 1 replies (of 1 total)

The topic ‘Exclude category from custom search’ is closed to new replies.