WordPress.org

Ready to get started?Download WordPress

Forums

Custom Query issue (1 post)

  1. indianabenny
    Member
    Posted 6 years ago #

    I'm working on a custom query function to search in my WP database for meta values of certain values. I haven't had any problems with any of my other meta values and searching for them, only my price meta. When I run the code in phpmyadmin on the database, I receive the results I expect (two posts that match my query), but when I run it in my template, I receive no results. I'm wondering if there is something about my query that WP is rejecting or filtering out. Here is the query:

    SELECT ID
    FROM $wpdb->posts
    LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id )
    LEFT JOIN $wpdb->term_relationships ON ( $wpdb->posts.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 $wpdb->term_taxonomy.term_id =6
    AND $wpdb->term_taxonomy.taxonomy = 'category'
    AND $wpdb->posts.post_status = 'publish'
    AND $wpdb->postmeta.meta_key = 'SUMMER-PRICE'
    AND $wpdb->postmeta.meta_value >= CAST( 1000 AS SIGNED )
    AND $wpdb->postmeta.meta_value <= CAST( 15000 AS SIGNED )
    LIMIT 0 , 30

    Any help would be greatly appreciated.

Topic Closed

This topic has been closed to new replies.

About this Topic