Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return instance of WP_Query instead of post array in find_related() #1520

Closed
Slamik opened this issue Oct 11, 2019 · 3 comments · Fixed by #1653
Closed

Return instance of WP_Query instead of post array in find_related() #1520

Slamik opened this issue Oct 11, 2019 · 3 comments · Fixed by #1653

Comments

@Slamik
Copy link

Slamik commented Oct 11, 2019

I propose to return WP_Query instance in find_related function instead of post array.

It's more native to Wordpress code style and developer can use standart loop in template or pass WP_Query instance to custom templater class.

@Slamik Slamik added the type:enhancement New feature or request. label Oct 11, 2019
@tlovett1
Copy link
Member

Seems like an interesting idea but this would break backwards compat.

@Slamik
Copy link
Author

Slamik commented Oct 14, 2019

To no to brake backward compatibility you can add an optional parameter.
For example:

	public function find_related( $post_id, $return = 5, $instance = false  ) {
		$args = array(
			'more_like'           => $post_id,
			'posts_per_page'      => $return,
			'ep_integrate'        => true,
			'ignore_sticky_posts' => true,
		);

		$query = new WP_Query( apply_filters( 'ep_find_related_args', $args ) );

		if ( $instance )
		    return $query;

		if ( ! $query->have_posts() ) {
			return false;
		}
		return $query->posts;
	}

@ayebare
Copy link

ayebare commented Jan 24, 2020

Looking into this.

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

Successfully merging a pull request may close this issue.

4 participants