Forums

Posts 2 Posts
[resolved] Connection to one page only? (11 posts)

  1. antwortzeit
    Member
    Posted 9 months ago #

    Hey,

    i absolutely love your plugin, we kind of develop every new project with it, because it's so simple to handle for our clients.

    I was just wondering, if there's a chance to create a connection from a custom post type (called 'persons') to one page only (based on an id or slug)?

    Thanks in advance.

    Best,

    Christian

    http://wordpress.org/extend/plugins/posts-to-posts/

  2. scribu
    Member
    Plugin Author

    Posted 9 months ago #

    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

  3. antwortzeit
    Member
    Posted 9 months ago #

    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 );
  4. antwortzeit
    Member
    Posted 9 months ago #

    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?

  5. scribu
    Member
    Plugin Author

    Posted 9 months ago #

    Yeah, it seems to be broken in 1.3.1. Works in the development version though.

  6. antwortzeit
    Member
    Posted 9 months ago #

    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

  7. antwortzeit
    Member
    Posted 9 months ago #

    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?

  8. scribu
    Member
    Plugin Author

    Posted 9 months ago #

    Define "breaks the connection".

  9. antwortzeit
    Member
    Posted 9 months ago #

    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!

  10. scribu
    Member
    Plugin Author

    Posted 9 months ago #

    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.

  11. antwortzeit
    Member
    Posted 9 months ago #

    Yap, perfekt, that worked. Thank you very much for your help!

Reply

You must log in to post.

About this Plugin

About this Topic