WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
[resolved] Search for Object in Connection Meta box not working (11 posts)

  1. brightidea
    Member
    Posted 2 years ago #

    I have multiple post types setup. Two of which are Articles and Products. I have setup a p2p connection between these. I have about 800 products and 30 something articles. After setting up the connection between two post types and then going to the backend and editing the article and trying to search from the p2p metabox for a product the search function doesnt work. I actually had everything setup and working on a different multisite installation and now after migrating the site to a different multisite installation this isnt working. Nothing else has changed. Im thinking there is a db value somewhere that wasnt updated when i made the migration.

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

  2. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    What exactly do you mean by "doesn't work"? 0 posts found? returns random posts?

  3. brightidea
    Member
    Posted 2 years ago #

    It simply says nothing found. I can click view all tab and it shows all available products. About 49 pages worth. But when i search something even if its the exact title of the product i get "Nothing Found".

  4. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    You're not using the latest version of P2P (1.2), are you?

  5. brightidea
    Member
    Posted 2 years ago #

    I upgraded to it and thats when i began having the problem. I did downgrade to the 1.1.5 i believe trying to diagnose problem and just havent reupgraded

  6. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    Please update back to 1.2 and deactivate all other plugins.

    If the problem goes away, activate one plugin at a time, until it starts happening again.

  7. brightidea
    Member
    Posted 2 years ago #

    ok i have reupgraded and now can see the "View all" button which i wasnt able to see before after the upgrade to 1.2. Still no results when searching for anything. Even if i copy and past a title in exactly.

  8. brightidea
    Member
    Posted 2 years ago #

    ok i deactivated all plugins and it magically worked! of course lol. Weird thing is i actually reactivated all plugins that were previously activated and its still working great. Thanks!!

  9. rolies106
    Member
    Posted 2 years ago #

    Hi scribu,

    I've got same problem like this one, I try to connect between 2 post type, "article" and "company", If I click "View All" link at edit "article" post it will show all "company" post, but if I type something in search box it'll show all post from another post type except from "company", this is my register script :

    http://pastebin.com/4prGR5RG

    I already try to disable all plugins and ONLY activated the Posts 2 Posts plugins but it still have same issue, I hope you can help me with this issue.

    Note : I'm using WordPress v.3.4 with WPMU enabled and p2p v.1.3.1 if that can help you with.

  10. rolies106
    Member
    Posted 2 years ago #

    Uppppssss...... I found this :

    http://wordpress.org/support/topic/plugin-posts-2-posts-metabox-search-not-respecting-connection?replies=7 and It solved my problem.

    Sorry not search all over your discussion before asking.

    Great plugins!

    Very thanks.

  11. JsonB123
    Member
    Posted 2 years ago #

    Hi All,

    Just wanted to weigh in here because I figured out with the help of the questions here as well as that linked post by rolies106 that you need to be really careful when modifying the main query with WordPress. I needed to make only the blog posts show on a search (instead of all pages) so I put a filter on pre_get_posts like so:

    function searchfilter( $query ) {
    	if ( $query->is_search ) {
    		$query->set( 'post_type','post' );
    	}
    	return $query;
    }
    add_filter( 'pre_get_posts', 'searchfilter' );

    Then I'm wondering why the Search function on Posts to Posts relations isn't working and only showing blog posts because I did this way after I set all of that up. Then it hit me: simply add the check on the if conditional !is_admin(). I did this and it's working great again because it's not adding this filter to any admin sections. This would also mess up ANY search functionality on the admin without that check.

    Fixed code:

    function searchfilter( $query ) {
    	if ( $query->is_search && ! is_admin() ) {
    		$query->set( 'post_type','post' );
    	}
    	return $query;
    }
    add_filter( 'pre_get_posts', 'searchfilter' );

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic