<?php $query = new WP_Query(['category_name' => 'news']); while ($query->have_posts()) { $query->the_post(); the_title(); } ?>
The 'category_name' parameter filters posts strictly by the exact category slug. So only posts assigned to the 'news' category are retrieved.
<?php
$args = [
'meta_query' => [
// Fill here
]
];
$query = new WP_Query($args);
?>The correct syntax uses 'key' and 'value' inside an array inside 'meta_query'. Option B matches this pattern exactly.
<?php $args = [ 'post_type' => 'product', 'category_name' => 'electronics' ]; $query = new WP_Query($args); ?>
Categories by default apply only to 'post' post type. Custom post types like 'product' need explicit taxonomy registration to use categories.
<?php $args = [ 'post_type' => 'post', 'meta_query' => [ 'relation' => 'OR', ['key' => 'color', 'value' => 'red', 'compare' => '='], ['key' => 'size', 'value' => 'large', 'compare' => '='] ], 'category_name' => 'sale' ]; $query = new WP_Query($args); ?>
The query filters posts in 'sale' category and meta conditions combined with OR, so posts matching either meta condition and in 'sale' category are returned.
Setting 'nopaging' to true disables pagination and ignores 'posts_per_page'. This is why 'posts_per_page' has no effect.
