• Hi folks,

    A bit of background info:
    I’m building a theme for a band and this theme is going to include tour posters as featured images within the custom post type of ‘concerts’.
    I already have the concert listings working as I’d like, using a custom field ‘_event_date’ to determine the order in which they’re displayed and whether they’re displayed at all (no concerts prior to today’s date are displayed).

    This was all well and good until I tried to have it check for the existence of ‘_thumbnail_id’ as a meta_key also and now within the query the meta_key for _thumbnail_id is cancelling out the meta_key for _event_date.

    Not good.

    Here’s the code I’m using just now to get the upcoming concerts out of the database:

    global $wpdb;
    $blog_prefix = $wpdb->prefix;
    $today = strtotime("today");
    
    $upcoming_concert_posters_query = "
    	SELECT *
    	FROM ".$blog_prefix."posts, ".$blog_prefix."postmeta
    	WHERE ID = post_id
    	AND post_type = 'concerts'
    	AND meta_key = '_event_date'
    	AND meta_value >= ".$today."
    	AND post_status = 'publish'
    	ORDER BY meta_value ASC
    	LIMIT 100
    ";
    
    $upcoming_concert_posters = $wpdb->get_results($upcoming_concert_posters_query, OBJECT);

    How can I change this to retain this current functionality but add an additional conditional which checks for the existence of _thumbnail_id?

    As you might have guessed, I suck with MySQL queries and any help would be greatly appreciated ??

    Cheers,
    Rab

Viewing 16 replies (of 16 total)
  • Thread Starter RSimpson

    (@rsimpson)

    Hi popper,

    Just a quick update to let you know that your code worked, I only had to make a couple of tiny minor adjustments (the term ‘postmeta’ needed to be in front of .meta_key and .post_id)

    ??

    I’m going to try adding multiple keys and let you know how I get on.

    Thanks again!

    Cheers,
    Robert

Viewing 16 replies (of 16 total)
  • The topic ‘mysql headache nightmare! (multiple meta_keys)’ is closed to new replies.