Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter cmoloney

    (@cmoloney)

    Thanks for your help doodlebee. Based on your suggestion I came up with a solution that works although perhaps its not the prettiest.

    I found that statement
    AND $wpdb->posts.ID !=
    works for single post ids, but it wasn’t working when i tried to feed it the $exclude array. The $exclude array was created by putting in this line of code
    $exclude[i++]=$post->ID;
    after the few feature entry displays at the top of the page.

    So I just created a super long $querystr using a foreach loop as shown here:

    $excludequerystr = '';
     foreach($exclude as $nodice) { $excludequerystr = $excludequerystr . " AND $wpdb->posts.ID != " . $nodice; } endforech;
     $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)
    	WHERE $wpdb->term_taxonomy.term_id = 329
    	AND $wpdb->term_taxonomy.taxonomy = 'category'
    	AND $wpdb->posts.post_status = 'publish'
    	" . $excludequerystr . "
    	AND $wpdb->postmeta.meta_key = 'agendadate'
    	AND $wpdb->postmeta.meta_value >= $today
    	ORDER BY $wpdb->postmeta.meta_value ASC
    	LIMIT 10
        ";
    
     $show = $wpdb->get_results($querystr, OBJECT);

    In case it was confusing you, here is an example of a page I created that has a few feature posts at the top and then the remaining posts listed below and on subsequent pages.

    https://www.theargentimes.com/travel/

    However on that page it was fine to display the results by most recent post id instead of sorting by a custom field.

    At the moment, the page I am working on is not ready, but for those who might be reading this in the future here is the page: https://www.theargentimes.com/agenda/

    Thread Starter cmoloney

    (@cmoloney)

    $exclude is the arraay of post IDs that I don’t want included in the search results.

    On the first page of the agenda category, I display the latest entries in all of the nine subcategories under agenda. The post IDs of those categories are put into the array called $exclude.

    At the bottom of that first page on all subsequent pages there is a list of more events – agenda posts – ordered by the custom field so the soonest event is listed first.

    I don’t want to repeat the special call out posts in the list. That is why I put their IDs in an array to be filtered from the results.

    I hope that makes sense. Any ideas?

    Thread Starter cmoloney

    (@cmoloney)

    iridiax – problem solved – thanks!

    Man that was a simple mistake. I just glanced at the examples thinking that was for pre 2.3 and have racking my brain over the code since then.

    You saved me a lot of time. Thanks again.

Viewing 3 replies - 1 through 3 (of 3 total)