Support

Account

Home Forums Add-ons Flexible Content Field filter posts by category

Helping

filter posts by category

  • In my flexible content group, I have a layout (vendors) in order to display a list on the front end.

    In my script, I’m currently using the following query:

    query_posts(array(
    ‘post_type’ => ‘vendors’,
    ‘numberposts’ => 100,
    ‘posts_per_page’ => 100,
    ‘orderby’ => ‘menu_order’,
    ‘order’ => ‘ASC’,
    ‘post__not_in’ => array(
    get_the_ID()
    ),
    ));

    I’m wanting to add the functionality to filter the list based on categories using the “taxonomy” field type, so I added a field to the layout (“categories”).

    If I hard code this to the query:

    ‘category__and’ => array(5),

    it will display only those vendors assigned to the category id 5.

    What I want is to be able to assign the categories based on the selection in the flexible content. I figured something like this would work:

    first

    category__and’ => array(get_sub_field(‘categories’)),

    but it does not. How can I fix this?

    Appreciate the help.

    (not an expert in PHP, obviously, so please go easy! Thx)

  • Never mind – I worked it out.

    First:

    $catarray = get_sub_field(‘categories’);

    then:

    ‘category__in’ => $catarray,

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.