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

CPT Support #510

Closed
pstamandjr opened this issue Jan 28, 2020 · 17 comments
Closed

CPT Support #510

pstamandjr opened this issue Jan 28, 2020 · 17 comments
Assignees
Labels
needs:feedback This requires reporter feedback to better understand the request. type:question Further information is requested.
Milestone

Comments

@pstamandjr
Copy link

I posted on #103, however it's a closed issue, so wanted to create a new one.

I'm running into the same issue, when trying to use a different endpoint than /wp-json/. I need to pull specific posts from a CPT.

Example I'm trying to use: https://WWW.URL.COM/wp-json/wp/v2/podcast?series=123

I've registered the CPT and set: "show_in_rest" => true

I keep getting this error:
image

However if I just use "https://WWW.URL.COM/wp-json/" for the endpoint it connects fine.

Any help would be appreciated!

@pstamandjr pstamandjr added the type:bug Something isn't working. label Jan 28, 2020
@jeffpaul jeffpaul self-assigned this Jan 29, 2020
@jeffpaul
Copy link
Member

@pstamandjr I'm assuming your sites in question are different WordPress instances and not within the same multisite (as you do not need to create External Connections for sites within the same multisite). In this case, if you set the second URL you noted as the External Connection URL in the External Connection screen and the connection gets established properly, then you should see the Distributor push menu on any instances of a published CPT. Are you not seeing the Distributor menu after publishing a CPT that's been registered correctly?

@jeffpaul jeffpaul added the needs:feedback This requires reporter feedback to better understand the request. label Jan 29, 2020
@pstamandjr
Copy link
Author

@jeffpaul Yes, you are correct. They are two separate WordPress instances.

In the external connection screen I can't pass in the URL of the direct CPT. (See screenshot below)

image

I can hit the main /wp-json/ which validates, however when trying to pass in a direct feed (ie: "/wp-json/wp/v2/podcast?series=385" it won't validate the URL.

Thanks for help.

@jeffpaul
Copy link
Member

@pstamandjr you don't need to pass in the specific CPT URL, just the main /wp-json URL for your site you're trying to connect to. Once that /wp-json external connection is made, you should be able to go into your CPT and push published posts to your connected site. Let me know if you're not seeing the Distributor push menu in the admin bar for published posts.

@pstamandjr
Copy link
Author

Ah, ok. That makes sense. I thought you could just connect directly to a specified feed, but I'm seeing them now and can customize to pair down what gets pulled in. Thanks again!

@pstamandjr
Copy link
Author

Hey @jeffpaul, do you have any documented examples of just pulling specific Custom Post type categories? Right now the /wp-json/ pulls all posts, including the custom post type we have setup for "podcasts", however there isn't a filter to narrow down to 1 specific category.

Basically, we need to pull specific CPT categories from. (ie: /wp-json/wp/v2/podcast?series=385)

Any help would be greatly appreciated!

@pstamandjr
Copy link
Author

@jeffpaul - Follow up to see if you could help with this. :)

@jeffpaul
Copy link
Member

@pstamandjr I'll check on that and get back to you

@pstamandjr
Copy link
Author

@jeffpaul Just checking in to see if you were able to check in on this. Thank you!

@jeffpaul
Copy link
Member

@pstamandjr there's currently no way to filter to specific categories of a CPT. It sounds like #428 may be the functionality you're looking for, correct?

@pstamandjr
Copy link
Author

@jeffpaul Yes, that is what we are looking to do, more or less. Rather than allowing the categories in the dropdown list to filter, can we hide them all together? So, we only pull in posts for this one specific category.

Basically, the 2nd site we are pushing to, should only have access to these specific posts and not be able to pull in others. Does that make sense?

@jeffpaul
Copy link
Member

@pstamandjr makes sense, probably best to note on #428 so we can include a hook to support that use case when someone gets to working on 428 (and we can then close this issue in favor of that one).

@pstamandjr
Copy link
Author

@jeffpaul That would be great! Do you know when it's slated for? Any change I can beg, borrow, or steal to have it done sooner. Hahha :)

@jeffpaul
Copy link
Member

@pstamandjr the 428 issue is currently unscheduled, but sitting on our roadmap a couple releases out so its unlikely to be available in the very near future. We do offer paid customization, implementation, and support packages should that be desired; if you're interested in that send me an email ([email protected]) and we can discuss available options.

@jeffpaul jeffpaul added type:question Further information is requested. and removed type:bug Something isn't working. labels Feb 25, 2020
@jeffpaul
Copy link
Member

@pstamandjr after chatting with our team, there is a filter around the post types that show in that pull list: https://10up.github.io/distributor/dt_available_pull_post_types.html.  If you only want a specific post type to show, you can do that using that filter.

You can also pass a query param to the pull page, if you want to filter that way.  So a URL like wp-admin/admin.php?page=pull&pull_post_type=page would automatically select Pages as the content type (though you can still choose a different content type manually).

Let me know if that doesn't cover the CPT question from this issue, otherwise we can close out this question.

@pstamandjr
Copy link
Author

pstamandjr commented Mar 2, 2020

@jeffpaul thank you again for the reply. We would definitely be leaning towards the first option of filtering out the post types that pull.

I'm trying to target that filter by the example here: #274 but it doesn't unfortunately filter it out. Would this still be current with the latest version?

add_filter( 'dt_available_pull_post_types', function ( $post_types, $remote_post_types, $local_post_types, $connection, $type ) {
	$post_types[] = [ 'name' => 'My Custom Post Type', 'slug' => 'my-cpt' ];
	return $post_types;
} );

@jeffpaul jeffpaul added this to the Future Release milestone Mar 5, 2020
@dkotter
Copy link
Collaborator

dkotter commented Mar 12, 2020

@pstamandjr That filter is in place in the current version (was added in 1.3.5). Looking at that example, the filter is using 5 arguments but in your add_filter call, you're not specifying how many arguments are accepted (so it defaults to 1). That will throw a PHP error and may be the reason it's not working.

I just tested this on my setup to only show Pages in the filter dropdown (by default it was showing Post and Pages), and it worked:

add_filter( 'dt_available_pull_post_types', function ( $post_types, $remote_post_types, $local_post_types, $connection, $type ) {
	return [
		[
			'name' => 'Pages',
			'slug' => 'page',
		]
	];
}, 10, 5 );

@jeffpaul
Copy link
Member

After discussing with @pstamandjr via email, his issue has been resolved so I'm closing this issue but happy to re-open for others with a similar need. Thanks!

@jeffpaul jeffpaul modified the milestones: Future Release, 1.6.0 Jun 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs:feedback This requires reporter feedback to better understand the request. type:question Further information is requested.
Projects
None yet
Development

No branches or pull requests

3 participants