• If you check out my code here, you can see that what I’m doing is grabbing the meta_value of the posts by category, printing that into a drop-down box, and then the second drop down box should populate all posts that contain BOTH the category (first drop down) and meta value (second drop down), but I can’t get the query right.

    Here is the relevant code (my query), currently if you debug and look at what’s being returned as json it’s just “0”

    $query = $wpdb->get_results(
                    "SELECT p.<code>ID</code>, pm.<code>meta_value</code> FROM {$wpdb->postmeta} pm
                    LEFT JOIN {$wpdb->posts} <code>p</code> ON <code>p</code>.<code>ID</code> = pm.<code>post_id</code>
                    LEFT JOIN {$wpdb->term_relationships} <code>tr</code> ON <code>p</code>.<code>ID</code> = <code>tr</code>.<code>object_id</code>
                    LEFT JOIN {$wpdb->term_taxonomy} <code>tt</code> ON <code>tr</code>.<code>term_taxonomy_id</code> = <code>tt</code>.<code>term_taxonomy_id</code>
                    WHERE <code>pm</code>.<code>meta_key</code> = 'substrate_box'
                    AND <code>pm</code>.<code>meta_key</code> = 'adhesion_box'
                    AND <code>pm</code>.<code>meta_value</code> = '$adh'
                    AND <code>p</code>.<code>post_status</code> = 'publish'
                    AND <code>p</code>.<code>post_type</code> = 'post'
                    AND <code>tt</code>.<code>taxonomy</code> = 'category'
                    AND <code>tt</code>.<code>term_id</code> = $cat
                    ");
Viewing 1 replies (of 1 total)
  • Thread Starter Remy Sheppard

    (@remy-sheppard)

    I’ve determined that the problem is my query. I don’t know how to query the database to get meta_value A from meta_key A when category = 1 AND meta_value B from meta_key B = 1

Viewing 1 replies (of 1 total)
  • The topic ‘AJAX request returns 0’ is closed to new replies.