Forums

Query to get specific meta_values from specific meta_key and post category (2 posts)

  1. rafaelrubirajr
    Member
    Posted 1 year ago #

    Hi there!

    I'm trying to get meta_values from specific meta_key and from specific post category.

    Here's the piece of code that I'm using:

    $querystr = "
            SELECT wpostmeta.meta_value
            FROM $wpdb->postmeta wpostmeta
    
            LEFT JOIN $wpdb->posts wposts ON wpostmeta.post_id = wposts.ID
        	LEFT JOIN $wpdb->term_relationships ON (wpostmeta.post_id = $wpdb->term_relationships.object_id)
        	LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
            WHERE wpostmeta.meta_key = 'my_meta_key'
            AND $wpdb->term_taxonomy.taxonomy = 'category'
        	AND $wpdb->term_taxonomy.term_id IN (5408)
    ";
    
        $results = $wpdb->get_results($querystr, OBJECT);

    With this code, I'm getting all values from $wpdb->postmeta, but not filtering by category? Are there something wrong with my query?

    Any help will be apreciated :)

  2. rafaelrubirajr
    Member
    Posted 1 year ago #

    In fact, this code is working very well. My apologies.

    Case closed :)

Topic Closed

This topic has been closed to new replies.

About this Topic