• The Following code works but not for all Taxonomies. Any thoughts as to why?

    $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); 
    
    $custom_post_type = 'shows';
    
    		 $querystr = "
    			SELECT *
    			FROM $wpdb->posts
    			LEFT JOIN $wpdb->postmeta AS date_value
    				ON($wpdb->posts.ID = date_value.post_id
    				AND date_value.meta_key = 'date_value')
    	  		INNER JOIN  $wpdb->term_relationships
    	              ON (wp_posts.ID = $wpdb->term_relationships.object_id)
    	  		INNER JOIN  $wpdb->term_relationships AS taxonomy
    	              ON ($wpdb->posts.ID = taxonomy.object_id)
    			WHERE $wpdb->posts.post_status = 'publish'
    				AND $wpdb->posts.post_type = '" . $custom_post_type . "'
    				AND date_value.meta_value >= '" . date('Ymd') . "'
    				AND ( $wpdb->term_relationships.term_taxonomy_id IN ($term->term_id)
    	  			AND taxonomy.term_taxonomy_id IN ($term->term_id) )
    			ORDER BY date_value.meta_value, $wpdb->posts.post_title
    		 	";
Viewing 1 replies (of 1 total)
  • Thread Starter SpidermanPuddin

    (@spidermanpuddin)

    I figured it out thanks to This Post. My code ended up looking like this:

    $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
    
    $custom_post_type = 'shows';
    
    		 $querystr = "
    			SELECT *
    			FROM $wpdb->posts
    			LEFT JOIN $wpdb->postmeta AS date_value
    				ON($wpdb->posts.ID = date_value.post_id
    				AND date_value.meta_key = 'date_value')
    	  		INNER JOIN  $wpdb->term_relationships
    	              ON (wp_posts.ID = $wpdb->term_relationships.object_id)
    	  		INNER JOIN  $wpdb->term_taxonomy
    	              ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    	        INNER JOIN  $wpdb->terms
    	              ON ($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id)
    			WHERE $wpdb->posts.post_status = 'publish'
    				AND $wpdb->posts.post_type = '" . $custom_post_type . "'
    				AND date_value.meta_value >= '" . date('Ymd') . "'
    				AND $wpdb->terms.term_id IN ( $term->term_id )
    			ORDER BY date_value.meta_value, $wpdb->posts.post_title
    		 	";
Viewing 1 replies (of 1 total)
  • The topic ‘Custom Taxonomy – Custom Select Query Problem’ is closed to new replies.