I'm attempting to query posts filtered by post type, taxonomy type, and term and display them as post counts grouped by published month.
I have a bit of code that does this perfectly as long as there are no spaces in the term title and no dashes in the term slug. Why could that be?
I've attemped using
escape('term-slug') with no success.
$posts_per_month = $wpdb->get_results( "SELECT DATE_FORMAT(post_date, '%Y-%m') AS month, COUNT(ID) AS count FROM $wpdb->posts AS wposts LEFT JOIN $wpdb->term_relationships AS tax_rel ON (wposts.ID = tax_rel.object_id) LEFT JOIN $wpdb->term_taxonomy AS term_tax ON (tax_rel.term_taxonomy_id = term_tax.term_taxonomy_id) LEFT JOIN $wpdb->terms AS terms ON (terms.term_id = term_tax.term_id) WHERE post_status = 'publish'" . $post_type_query . "AND terms.name = 'shorelineorwaterway' AND term_tax.taxonomy = 'cleanup_type' GROUP BY month", OBJECT_K );
If I remove the spaces from the term title and the dashes from the term slug it works perfectly. If I try no dashes in the slug and spaces in the title it returns an empty array. Similarly, if I try dashes in the slug and no spaces in the title it doesn't work.
Is there an obvious reason this could be happening?