Skip to content
This repository was archived by the owner on May 2, 2024. It is now read-only.
This repository was archived by the owner on May 2, 2024. It is now read-only.

post__not_in doesn't work as expected.  #28

Description

@Kluny

What I did

Called the postfinder like this.

pf_render( RELATED_ARTICLES_FIELD, $values, array(
	'limit' => 3,
	'args' => array( 'post__not_in' => array( $post_id = 135) )
));

What I got

Passing post ID to the args array is intended to prevent the current post from appearing in the choices. The resulting HTML includes this data-args array:

data-args="{"post_type":"post","posts_per_page":10,"post_status":"publish","suppress_filters":false,"post__not_in":["135"]}

Post 135 is excluded from the PF list as expected. However, after choosing a couple of items and updating the post, the data-args array looks like this:

data-args="{"post_type":"post","posts_per_page":10,"post_status":"publish","suppress_filters":false,"post__not_in":[133,130]}

Possible cause

As you can see, 135 isn't in the post__not_in array, and as a result, the current post appears in the picker. I think the post__not_in array is being overridden instead of merged. Right here:

https://github.com/10up/post-finder/blob/master/includes/classes/NS_Post_Finder.php#L300

// if we have some ids already, make sure they aren't included in the recent posts
	if ( ! empty( $post_ids ) ) {
		$args['post__not_in'] = $post_ids;
	}

Should be

$args['post__not_in'] = array_merge( $post_ids, $args['post__not_in'] );

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions