Plugin Author
scribu
(@scribu)
You can use the ‘p2p_connectable_args’ filter, setting $args['page'] = 'some-slug':
https://github.com/scribu/wp-posts-to-posts/wiki/Admin-box-filters
Mh, could’nt get that to work – but used this instead:
function unternehmensleitung( $show, $ctype, $post ) {
if ( 'unternehmensleitung' == $ctype->name )
if($post->ID == 11) { return $show; } else { return false; }
return $show;
}
add_filter( 'p2p_admin_box_show', 'unternehmensleitung', 50, 3 );
That just hides the box on the other pages, but breaks the connection itself – it doesn’t find the posts to connect anymore.
So i went back to your suggestion, but the filter doesn’t seem to work. It doesn’t even dump the variables:
function unternehmensleitung( $args, $ctype, $post_id ) {
var_dump($ctype->name);
var_dump($ctype->get_direction());
if ( 'unternehmensleitung' == $ctype->name && 'to' == $ctype->get_direction() ) {
$args['page'] = 'unternehmen';
}
return $args;
}
add_filter( 'p2p_connectable_args', 'unternehmensleitung', 10, 3 );
Any idea what goes wrong?
Plugin Author
scribu
(@scribu)
Yeah, it seems to be broken in 1.3.1. Works in the development version though.
Right, the filter works here. But it doesn’t do, what i expected it to do. The connection admin box still shows up, still shows “Create Connection” and just fails by trying the latter if not on the page i specified.
Additionally, the development version breaks my other approach via p2p_admin_box_show with an error:
Fatal error: Cannot break/continue 1 level in /is/htdocs/XXXXXXXXXX/www/wp-content/plugins/posts-to-posts/admin/box-factory.php on line 47
Back at 1.3.1 my other approach does hide the box, but also breaks the connection as mentioned above:
function unternehmensleitung( $show, $ctype, $post ) {
if ( 'unternehmensleitung' === $ctype->name && $post->ID !== '11' ) {
$show = false;
}
return $show;
}
add_filter( 'p2p_admin_box_show', 'unternehmensleitung', 50, 3 );
Why can it break the connection, when it doesn’t even change anything on that very page?
Plugin Author
scribu
(@scribu)
Define “breaks the connection”.
When you click on “All Connections” (sorry if i translate this wrong, working in german) or if you search for a connected item, it just doesn’t return anything.
By the way: thanks for your endurance!
Plugin Author
scribu
(@scribu)
The fatal error in the dev version was fixed.
The “breaking of the connection” occurs because the filter is also run in the AJAX request that’s done for retrieving connection candidates. You should also check $ctype->get_direction() in your callback.
Yap, perfekt, that worked. Thank you very much for your help!