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

Register connection type to a specifc page #552

Open
nunospot opened this issue Jul 13, 2017 · 3 comments
Open

Register connection type to a specifc page #552

nunospot opened this issue Jul 13, 2017 · 3 comments

Comments

@nunospot
Copy link

Hello,

Is there a way to register a post type to a specific template page?

Example:

function connection() {
p2p_register_connection_type( array(
'name' => 'connection',
'from' => get_page_template('the_template.php'), //the page template
'to' => 'the_post_type'
) );
}

Connect a post type "the_post_type" to the pages that have the "the_template.php" template?

Thank you.

@kkerley
Copy link

kkerley commented Nov 20, 2017

Did you ever end up figuring out if this was possible? I just inherited a project using this plugin and need to accomplish something similar.

@nunospot
Copy link
Author

No. This was a "nice to have" thing :\

@chrisgherbert
Copy link

I don't think you can restrict the actual connection to a specific page template, but you can only show the p2p interface on certain templates using the p2p_admin_box_show filter: https://github.com/scribu/wp-posts-to-posts/wiki/Actions-and-filters

<?php
function restrict_p2p_box_display( $show, $ctype, $post ) {
	if ( 'posts_to_pages' == $ctype->name && 'to' == $ctype->get_direction() ) {
		return ( 'YOUR-TEMPLATE.php' == $post->page_template );
	}

	return $show;
}

add_filter( 'p2p_admin_box_show', 'restrict_p2p_box_display', 10, 3 );

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

No branches or pull requests

3 participants