WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [Plugin: WordPress Related Posts] filter by postmeta (2 posts)

  1. henri
    Member
    Posted 3 years ago #

    Hi all

    I use WordPress Related Posts plugin and I want to filter the result by meta_key and meta_value. I try to change the query inside the plugin like this but I must miss something :

    $q = "
    SELECT p.ID, p.post_title, p.post_content,p.post_excerpt, p.post_date,  p.comment_count, p.post_id, p.meta_value, p.meta_key, count(t_r.object_id) as cnt
    FROM $wpdb->term_taxonomy t_t, $wpdb->term_relationships t_r, $wpdb->posts p, $wpdb->postmeta pm
    WHERE t_t.taxonomy ='post_tag'
    AND t_t.term_taxonomy_id = t_r.term_taxonomy_id
    AND t_r.object_id  = p.ID = p.post_id
    AND (t_t.term_id IN ($taglist))
    AND p.ID != $post->ID != p.post_id
    AND p.post_status = 'publish'
    AND p.post_date_gmt < '$now'
    AND pm.meta_key = 'custom_field_disponibilite'
    AND pm.meta_value = 'DISPO'
    GROUP BY t_r.object_id ORDER BY cnt DESC, p.post_date_gmt DESC $limitclause;";

    If you have any input feel free to comment!

  2. henri
    Member
    Posted 3 years ago #

    Here is the solution brought by Amaury Balmer (http://www.herewithme.fr/)

    $q = "
    	SELECT p.ID, p.post_title, p.post_content,p.post_excerpt, p.post_date,  p.comment_count, count(t_r.object_id) as cnt
    	FROM $wpdb->term_taxonomy t_t, $wpdb->term_relationships t_r, $wpdb->posts p, $wpdb->postmeta pm
    	WHERE t_t.taxonomy ='post_tag'
    	AND t_t.term_taxonomy_id = t_r.term_taxonomy_id
    	AND t_r.object_id = p.ID
    	AND p.ID = pm.post_id
    	AND (t_t.term_id IN ($taglist))
    	AND p.ID != $post->ID
    	AND p.post_status = 'publish'
    	AND p.post_date_gmt < '$now'
            AND pm.meta_key = 'custom_field_disponibilite'
            AND pm.meta_value = 'DISPO'
    	GROUP BY t_r.object_id ORDER BY cnt DESC, p.post_date_gmt DESC $limitclause;";

Topic Closed

This topic has been closed to new replies.

About this Topic