Support

Account

Home Forums ACF PRO Using post type as custom field for filter post types

Helping

Using post type as custom field for filter post types

  • I’m trying to filter post types by another post type selected as custom field.

    courses:
    power
    water

    classes:
    class1:
    title : class1
    parent_course : power

    my code in single-course.php:

    $id = get_the_id();
    $classes = get_posts(array(
    ‘numberposts’ => -1,
    ‘post_type’ => ‘class’,
    ‘meta_key’ => ‘parent_course’,
    ‘meta_value_num’ => $id
    ));

    but no data retrieved or all classes without any filtering retrieved.\

    any idea?

    thanks

  • It depends on what type of field parent_course is. The query you need to use will depend on what type of field it is and the way that field stores data in the DB https://www.advancedcustomfields.com/resources/query-posts-custom-fields/

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

The topic ‘Using post type as custom field for filter post types’ is closed to new replies.