This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Forum Replies Created

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • in reply to: 'post_parent' != 1 #24516
    am12313am12313
    Participant

    Hey, Thanks.

    I need to be able to do this programmatically. Can I use the above code?

    The reason is: I need to exclude all posts where post_parent == 0. In other words, I want only child posts to appear in the search.

    My solution was this:

    $args1 = [
    ‘post_type’ => ‘wines’,
    ‘post_parent’ => 0,
    ‘nopaging’ => true,
    ‘fields’ => ‘ids’
    ];
    $ids = get_posts( $args1 );
    add_filter( ‘asp_query_args’, ‘asp_exclude_by_ids’, 10, 2 );

    function asp_exclude_by_ids( $args, $id ) {

    $args[‘post__not_in’] = $ids;
    return $args;
    }

    However, that code does not appear to be compatible.

    Thank you.

    in reply to: 'post_parent' != 1 #24508
    am12313am12313
    Participant

    Hi! Thanks for your reply!

    I’m actually looking to exclude posts; however, this code does not appear to work:

    add_filter( ‘asp_query_args’, ‘asp_exclude_by_ids’, 10, 2 );

    function asp_exclude_by_ids( $args, $id ) {

    $args[‘post__not_in’] = array(539);
    return $args;
    }

    Thank you

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