WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
[resolved] Metabox search not respecting connection (7 posts)

  1. sstasio
    Member
    Posted 2 years ago #

    Hi all,

    I've got my posts connected to a custom post type called destination. When a post is written, I'd like the author to assign it to a destination. The problem is that the search brings up all slugs, regardless of the connection set, that match the term while listing the connected 'posts' respects the connection. Have I set up my connection incorrectly, or is this a known issue when using the search? Any help is greatly appreciated. Here is my connection code:

    //Posts 2 Post Connections
    function my_connection_types() {
    	// Make sure the Posts 2 Posts plugin is active.
    	if (!function_exists('p2p_register_connection_type'))
    		return;
    
    	//events
    
    		p2p_register_connection_type( array(
    			'id' => 'event_destination',
    			'from' => 'event',
    			'to' => 'destination',
    			'sortable' => 'any'));		
    
    		p2p_register_connection_type( array(
    			'id' => 'event_recprogram',
    			'from' => 'event',
    			'to' => 'recprogram',
    			'sortable' => 'any'));
    
    		p2p_register_connection_type( array(
    			'id' => 'event_project',
    			'from' => 'event',
    			'to' => 'project',
    			'sortable' => 'any'));
    
    	//posts
    
    		p2p_register_connection_type( array(
    			'id' => 'post_destination',
    			'from' => 'destination',
    			'to' => 'post',
    			'sortable' => 'any'));	
    
    		p2p_register_connection_type( array(
    			'id' => 'post_recprogram',
    			'from' => 'post',
    			'to' => 'recprogram',
    			'sortable' => 'any'));
    
    		p2p_register_connection_type( array(
    			'id' => 'post_project',
    			'from' => 'post',
    			'to' => 'project',
    			'sortable' => 'any'));	
    
    	//people
    
    		p2p_register_connection_type( array(
    			'id' => 'employee_manager',
    			'from' => 'employee',
    			'to' => 'employee',
    			'cardinality' => 'one-to-many',
    			'sortable' => 'any',
    			'title' => array( 'from' => 'Manages', 'to' => 'Managed by' )));
    
    	//managed
    
    		p2p_register_connection_type( array(
    			'id' => 'recprogram_managers',
    			'from' => 'employee',
    			'to' => 'recprogram',
    			'sortable' => 'any'));
    
    		p2p_register_connection_type( array(
    			'id' => 'project_manager',
    			'from' => 'project',
    			'to' => 'employee',
    			'cardinality' => 'many-to-many',
    			'sortable' => 'any',
    			'title' => array( 'from' => 'Project Manager', 'to' => 'Projects Managed')));
    
    		p2p_register_connection_type( array(
    			'id' => 'destination_manager',
    			'from' => 'destination',
    			'to' => 'employee',
    			'cardinality' => 'many-to-many',
    			'sortable' => 'any',
    			'title' => array( 'from' => 'Destination Manager', 'to' => 'Destinations Managed')));
    
    			}
    
    add_action( 'init', 'my_connection_types', 100 );

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

  2. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    So what you're saying is that, in the 'event_destination' metabox, when you search for a destination, you get posts that are not destinations at all.

    And this happens for all the P2P metaboxes?

  3. sstasio
    Member
    Posted 2 years ago #

    Yes, that is correct. I haven't tested all of the connections that I made, but will do so now. I'll post the results shortly. Thanx for your awesome plugin!

    Sean

  4. sstasio
    Member
    Posted 2 years ago #

    Scribu,

    Yes, all metaboxes produce the same behavoir.

    Sean

  5. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    Can't reproduce using the latest version (1.1.2).

    Try switching to the default theme. Then, try disabling all other plugins.

  6. sstasio
    Member
    Posted 2 years ago #

    I figured it out, I used the following code to add my custom post types to search:

    //Add Custom Post Types to Search
    //function filter_search($query) {
    //    if ($query->is_search) {
    //	$query->set('post_type', array('post', 'employee', 'project', 'recprogram', 'partner', 'destination', 'event'));
    //    };
    //    return $query;
    //};
    //add_filter('pre_get_posts', 'filter_search');

    oops...

  7. daxitude
    Member
    Posted 2 years ago #

    I had the same problem and solved by adding a ! is_admin conditional to the if statement.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic