Posts 2 Posts
[resolved] Create a new post from the connect metabox (9 posts)

  1. Koff
    Posted 5 years ago #

    I have custom type person, and custom type hobby.
    If add a connection from person to hobbies.

    is it possible to add hobby from the connection metabox?

    Is this supported ?

  2. scribu
    Plugin Author

    Posted 5 years ago #

    No, it's not supported and it's not on the roadmap either.

  3. Koff
    Posted 5 years ago #


    Thank you for your answer.
    Is there a good reason for this not to be on the roadmap?

    i made some changes to the code:

    \ui\boxes.php:55 added:

    function add_to_post() {
    		$my_post = array(
    		 'post_title' => $_POST['post_title'],
    		 'post_author' => 1,
    		 'post_type' => $this->to
    		wp_insert_post( $my_post );

    \ui\boxes.php:112 added:

    <a href="#" class="p2p-addnew button" name="p2p-addnew">
    		<?php _e( 'Add new', 'posts-to-posts' ); ?>

    ui.css:22 added

    .p2p-footer .p2p-addnew {
    	float: right;

    and ui.js:208 added:

    // Delegate p2p-addnew
    	$metabox.delegate('.p2p-addnew', 'click', function() {
    		var $button = $(this);
    		if ( $button.hasClass('inactive') )
    			return false;
    		var $x =$metabox.find('.p2p-search :text').val();
    		var data = $.extend( base_data, {
    			action: 'p2p_connections',
    			subaction: 'add_to_post',
    			post_title: $x
    		} );
    		$.post(ajaxurl, data, function(response) {
    			find_posts(1, $x);
    		return false;

    And the result is as suggested in
    this post.

    What do you say?

  4. scribu
    Plugin Author

    Posted 5 years ago #

    Thanks for sharing your solution.

    However, it's very confusing, at the moment, from a user experience standpoint.

    First thing I did after applying the changes is to click the "Add new" button. Since the search box was empty, it behaved just like the "Recent" button.

    Instead of automatically using what's in the search field, you should be prompted to enter the post title (by changing the label of the search field and setting focus on the field).

    Since search is case insensitive, it's very unlikely that what you searched for would be the final post title that you wanted.

    If you would like to take another swing at this, please consider forking on github and then submitting a pull request:


    If you're not confortable doing that, at least send me the modified plugin files in a zip - it's faster for both of us and less error prone. My email: mail@scribu.net

    PS: I was unwilling to add something like this because I was over-complicating it. You have opened my eyes! :)

  5. Koff
    Posted 5 years ago #


    You are absolutely right.

    I changed the code to do this the same interface as Add Category.
    I think its much better now.

    I will send you the code by mail.


    p.s. I chose to add the post as draft, thinking the user has to complete their details. I am not sure though this the right behavior.

  6. scribu
    Plugin Author

    Posted 5 years ago #

    Yes, creating it as a draft makes the most sense.

    The development version (0.8-alpha) incorporates the ability to create posts from the connections box.

  7. bonsak
    Posted 4 years ago #

    I realize this is an old tread, but where in the code should i look to change the status of the posts created this way, to published instead of draft? I tried searching through the plugin files, but i couldnt find anything.( meaningfull to a php noob like myself :) )


  8. scribu
    Plugin Author

    Posted 4 years ago #

    You can use the 'p2p_new_post_args' filter:


  9. bonsak
    Posted 4 years ago #



Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Posts 2 Posts
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic