• Hi everybody,

    I know this questions have been asked many times, but I can’t get my code work ;-(

    I’m trying to filter a listing aof posts with a query base on two custom fields.

    So here’s my code :

    $today = date( 'd-m-Y' );
                    $where .= " AND ($wpdb->posts.ID in (
                    select $wpdb->postmeta.post_id from $wpdb->postmeta
                    JOIN $wpdb->postmeta meta1 ON meta1.post_id = p.ID
    		JOIN $wpdb->postmeta meta2 ON meta2.post_id = p.ID
                    WHERE meta1.meta_key = 'end_date'
    	        AND meta2.meta_key >='".$today."'
    	        AND meta1.meta_value = '2-3-ans'
    	        AND meta2.meta_value = 'on'))";
                    return $where;

    Surely there’s something I miss because it’s not working ;-(

    The original code was

    $where .= " AND ($wpdb->posts.ID in (select $wpdb->postmeta.post_id from $wpdb->postmeta where $wpdb->postmeta.meta_key='end_date' and $wpdb->postmeta.meta_value>='".$today."')) ";

    and works

    Thanks in advance guys for helping

Viewing 1 replies (of 1 total)
  • The last time I did something like this it turned out to be that the date wasn’t formatted the way I thought it was. The best place to start with something like this is to look at the actual sql statement that’s being build by examining the value of

    $wp_query->request

    If you install the developer tools plugin, you can use

    krumo($wp_query->request );

    in place of echo and it will give you a nicer presentation of the results. If you can’t figure out what the sql statement is doing, paste it back here and we’ll see if we can help.

Viewing 1 replies (of 1 total)

The topic ‘Multiple custom field based query’ is closed to new replies.