WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
Update related posts from front end select (1 post)

  1. Pete
    Member
    Posted 1 year ago #

    I have a front end form which lets users edit posts, specifically a custom post type called strain, when the page loads it makes a GET request to populate the form fields. In the form is a drop down select menu displaying titles or a second custom post type called Places. The Strain post they are editing was connected to a Place when they first created the Strain Post. That works fine.....

    This is what I use to display all the users places in the drop down select

    <select name="dispensary_name" id="">
    <?php
    	global $post;
    	wp_get_current_user();
    	$args = array( 'numberposts' => -1,'post_type' => 'place', 'author' => $current_user->ID );
    	$posts = get_posts($args);
    
    foreach( $posts as $post ) : setup_postdata($post); ?>
            <option value="<? echo $post->ID; ?>"><?php the_title(); ?></option>
    <?php endforeach; ?>
    </select>

    When they submit the updates I use this to make the connection

    $select = $_POST['dispensary_name'];
    		p2p_type( 'place_strain' )->connect( $post_id, $select, array(
    			'date' => current_time('mysql')
    		));

    This is not updating the connection, the $post_id is the strain post they are editing, and $select is the Places post ID from the select menu, I use the same submit code when creating the initial connection and that works fine.

    How can I make this update the Strain connection to a the new Place selected?

    Here is my connection information

    function my_connection_types() {
    	p2p_register_connection_type( array(
    	'name' => 'place_strain',
    	'admin_box' => array(
    		'show' => 'to',
    		'context' => 'side'
    	  ),
    	'from' => 'strains',
    	'to' => 'place',
    	'reciprocal' => false,
    	'cardinality' => 'many-to-one',
    	'title' => array( 'from' => 'Dispensary', 'to' => 'Strains' )
    	) );
    }

    Thanks

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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.