Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1135729

    I am creating a page and it has some Masonry posts divided by blocks.

    Block 1
    Masonry with category salads selected.

    Block 2
    Masonry with category meat selected.

    Block 3
    Masonry with category breakfast selected.

    Block 4
    Masonry with category dinner selected.

    Meat and breakfast have no posts yet, but it is showing everything in posts, instead of not showing anything until I add posts.

    Why if I select Breakfast and it has no posts, it shows everything by itself?

    Thanks.

    #1136848

    Hey peterolle,

    Thank you for the update.

    The masonry element is using the post__in parameter to return the posts from the selected category. If the category is empty, it will return all posts.

    NOTE: Ticket #28099: Passing an empty array to post__in will return has_posts() as true (and all posts will be returned). Logic should be used before hand to determine if WP_Query should be used in the event that the array being passed to post__in is empty.

    // https://developer.wordpress.org/reference/classes/wp_query/

    You can always remove the element if there is no post yet.

    Best regards,
    Ismael

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.