Post field: how to filter posts of certain categories?

Support General Post field: how to filter posts of certain categories?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #31692
    dhuydhuy
    Participant

    Hi Support team,

    I've been using the post field to manually select the related posts for new my posts. When the number of posts increase, it's become frustrating to select among hundreds of post.
    I'm looking for a way to exclude certain categories that I don't need.

    Please take a look.
    Thanks,
    Huy

    #31696
    Long NguyenLong Nguyen
    Moderator

    Hi,

    You can use the setting query_args to filter posts by taxonomy as well. Please read more on the documentation
    https://docs.metabox.io/fields/post/#settings
    https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters

    #31814
    dhuydhuy
    Participant

    Just some simple lines of code to make my life easier.
    Thanks for your swift respond.

    #31836
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Here is an example:

    'fields' => [
        [
            'name'        => 'Select a post',
            'id'          => 'my_post',
            'type'        => 'post',
            'post_type'   => 'post',
            'field_type'  => 'select_advanced',
            'query_args'  => [
                'tax_query' => [
                    [
                        'taxonomy' => 'category',
                        'field'    => 'slug',
                        'terms'    => [ 'aciform', 'comedy' ],
                    ],
                ],
            ],
        ],
    
    ],
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.