WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. Koff
    Member
    Posted 3 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
    Member
    Plugin Author

    Posted 3 years ago #

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

  3. Koff
    Member
    Posted 3 years ago #

    Hi,

    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 );
    		die(1);
    	}

    \ui\boxes.php:112 added:

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

    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();
    		$button.addClass('inactive');
    
    		var data = $.extend( base_data, {
    			action: 'p2p_connections',
    			subaction: 'add_to_post',
    			post_title: $x
    		} );
    		$.post(ajaxurl, data, function(response) {
    			find_posts(1, $x);
    			$button.removeClass('inactive');
    		});
    
    		return false;
    	});

    And the result is as suggested in
    this post.

    What do you say?

  4. scribu
    Member
    Plugin Author

    Posted 3 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:

    https://github.com/scribu/wp-posts-to-posts/

    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
    Member
    Posted 3 years ago #

    Hi,

    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.

    Thanks,
    Koff

    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
    Member
    Plugin Author

    Posted 3 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
    Member
    Posted 2 years ago #

    Hi
    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 :) )

    Cheers
    Bonsak

  8. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    You can use the 'p2p_new_post_args' filter:

    https://github.com/scribu/wp-posts-to-posts/wiki/Admin-box-filters

  9. bonsak
    Member
    Posted 2 years ago #

    Sweet!

    -b

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic