The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

What is wrong with this query? (2 posts)

  1. Weblinkscreations
    Posted 3 years ago #


    Im trying to get related posts for actual post that user is seeing (custom post type named property)

    At the moment it only gives me the related post from the same 'pcategory' which are the categories for the post type.

    What I need is same post type category as it is now and also with the same post type custom field ('location').

    Tried many ways but was not able to get it. What is wrong with the query?

    $querystr = "
    SELECT * 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)
    LEFT JOIN $wpdb->terms ON($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id)
    WHERE $wpdb->terms.term_id in (".$catId.")
    AND $wpdb->term_taxonomy.taxonomy = 'pcategory'
    AND $wpdb->posts.post_status = 'publish'
    AND $wpdb->posts.post_type = 'property'
    AND $wpdb->postmeta.meta_key = 'location'

    ORDER BY $wpdb->posts.ID LIMIT 0 ,$limit";

  2. vtxyzzy
    Posted 3 years ago #

    DUPLICATE. Please continue with your original post: http://wordpress.org/support/topic/query-database?replies=2

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.