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

Add new API's to make it easier to get all the relationships for a given post type #82

Open
fabiankaegy opened this issue Jan 3, 2025 · 0 comments

Comments

@fabiankaegy
Copy link
Member

As it stands today, everything in WP Content Connect is tied to individual posts.

This solves most usecases. But when working with the Core Query loop for example you need to be able to get all the possible relationships given only a post type. So there is no post involved.

I was able to work around that by getting a random post of that post type:

$post_type = $request->get_param( 'post_type' );

// get a random post of the given post type
$the_post = get_posts(
	[
		'post_type'   => $post_type,
		'numberposts' => 1,
	]
);

if ( empty( $the_post ) ) {
	return new WP_REST_Response( [], 200 );
}

$the_post = $the_post[0];

$result        = [];
$relationships = apply_filters( 'tenup_content_connect_post_relationship_data', [], $the_post );

But that feels rather hacky. And having to manually call apply_filters here also feels much too low level for this kind of thing.

Ideally we should have a high level API to retrieve the relationships that are possible given a post type. And whilst we are at it also the relationships that are possible given a single post / user.

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

No branches or pull requests

1 participant