‘post’ for post_type does not work for WP_Query
-
Hi.
I have those arguments for my query.
$args2 = array( 'post_type' => 'post', 'post_status' => 'any', 'cat' => $category_id, 'posts_per_page' => -1, // Recupera tutti i post corrispondenti ai criteri 'author' => $user_id );I log this array and result is this
[11-Sep-2023 10:22:34 UTC] stampa array args: [11-Sep-2023 10:22:34 UTC] post [11-Sep-2023 10:22:34 UTC] any [11-Sep-2023 10:22:34 UTC] 5841 [11-Sep-2023 10:22:34 UTC] -1 [11-Sep-2023 10:22:34 UTC] 17which looks fine. Than I do this
$query2 = new WP_Query($args2);Than I try to log the $query2 with
error_log($query2->request);and the result of this log is a query like this
SELECT hAvlYjZV_posts.* FROM hAvlYjZV_posts LEFT JOIN hAvlYjZV_term_relationships ON (hAvlYjZV_posts.ID = hAvlYjZV_term_relationships.object_id) WHERE 1=1 AND ( hAvlYjZV_term_relationships.term_taxonomy_id IN (5841)) AND hAvlYjZV_posts.post_author IN (17) AND hAvlYjZV_posts.post_type IN ('libri', 'ricette', 'cpt_interviste', 'rubriche_originali') AND ((hAvlYjZV_posts.post_status <> 'trash' AND hAvlYjZV_posts.post_status <> 'auto-draft')) GROUP BY hAvlYjZV_posts.ID ORDER BY hAvlYjZV_posts.post_date DESCNow the problem… post_type seems to filter by ‘libri’, ‘ricette’, ‘cpt_interviste’, ‘rubriche_originali’ (which are custom post types in my implementation) but in my $args2 I explicitly asked for
'post_type' => 'post',Why do I have this statement wrong in WP_Query??? Any help here?
Thanks. Ioria
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
The topic ‘‘post’ for post_type does not work for WP_Query’ is closed to new replies.