• 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 ??

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Query to get specific meta_values from specific meta_key and post category’ is closed to new replies.