WordPress.org

Ready to get started?Download WordPress

Forums

WordPress Database Query (1 post)

  1. Weblinkscreations
    Member
    Posted 1 year ago #

    Hi all,

    Im using a theme that uses this code to get the related posts (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 and also with the same post type custom field ('location').

    Tried many ways but was not able to get it. Can someone help me on this?

    Thanks in advance.

    $query = "select $wpdb->posts.* from $wpdb->posts,$wpdb->terms,$wpdb->term_taxonomy,$wpdb->term_relationships where $wpdb->terms.term_id in (".$catId.") and $wpdb->terms.term_id = $wpdb->term_taxonomy.term_id and $wpdb->term_taxonomy.taxonomy = 'pcategory' and $wpdb->term_taxonomy.term_taxonomy_id =
    $wpdb->term_relationships.term_taxonomy_id AND $wpdb->posts.post_status = 'publish' and $wpdb->term_relationships.object_id = $wpdb->posts.ID and $wpdb->posts.ID != ".$post->ID." group by $wpdb->posts.ID order by $wpdb->posts.ID LIMIT 0 ,$limit";

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.