WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
[resolved] Search in admin connection box (7 posts)

  1. dotsdigits
    Member
    Posted 1 year ago #

    The current admin connection box that is displayed in the post screen(in the backend) where you can create a connection uses a search function.

    Now it uses a neat Ajax search based on the title string. Is this function extendible?

    We are looking to extend this function to not only title fields, but also meta fields. Can anyone post some pointers on where to look?

    Thanks in advance!

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

  2. scribu
    Member
    Plugin Author

    Posted 1 year ago #

    In admin/box.php, there's a call to the get_connectable() method:

    https://github.com/scribu/wp-posts-to-posts/blob/master/admin/box.php#L181-188

  3. dotsdigits
    Member
    Posted 1 year ago #

    Thanks for setting me in the right direction. I've been at it today and learned a lot about your plugin, but I did not managed to pull it off.
    Currently I tried (at box.php L180):

    $extra_qv = array_merge( self::$admin_box_qv, array(
    	'p2p:context' => 'admin_box_candidates',
    	'p2p:search' => $search,
    	'p2p:page' => $page,
    	'p2p:per_page' => 20,
    	'meta_query' => array(
    		array(
    		        'key' => '_personaldata_firstname',
    			'value' => $search,
    			'compare' => 'LIKE',
    			)
    		)
    	) );

    With this I could not find the meta field _personaldata_firstname. According to https://codex.wordpress.org/Class_Reference/WP_Query this could be used, but how does your plugin handle this?

  4. scribu
    Member
    Plugin Author

    Posted 1 year ago #

    It's not an issue with P2P, but with WP_Query.

    You're telling it to find posts that contain $search both in post_content AND in the '_personaldata_firstname' custom field.

    You should take a look at how plugins that enhance WP's search functionality handle this.

  5. dannybatista
    Member
    Posted 1 year ago #

    I'm just trying to display extra meta information next to the title of the possible connections. I've been messing with box.php all day and still can't figure it out. dotsdigits where you able to figure anything out that might help me display post meta in the default admin box?

  6. dotsdigits
    Member
    Posted 1 year ago #

    Hi dannybatista,

    It took me a while, but I found no really suitable solution with the P2P and the advanced search combined. As a solution, I've build an indexer that loops through the posts, and replaces the titles with the meta values.

    I believe this solution is better in the end for our cause because the speed of the search (through already 2000 posts, is within 2 seconds). When using search everything plugin combined with P2P, a search took me 26 seconds. Not usable for my clients of course.

    Here is the core code of the indexer, I've build this as a custom plugin, with its own admin page.

    public function startIndex(){
    	$args = array(
    		'post_type' => 'studenten',
    		'post_status' => 'publish',
    		'posts_per_page' => 100,
    		'offset' => 0,
    	);
    	query_posts( $args );
    	if(have_posts()) :
    		while (have_posts()) : the_post();
    			$meta_voornaam = get_post_meta(get_the_id(), '_persoonsgegevens_voornaam');
    			$meta_achternaam = get_post_meta(get_the_id(), '_persoonsgegevens_achternaam');
    			$meta_email = get_post_meta(get_the_id(), '_persoonsgegevens_email');
    			$combined_meta = trim( $meta_voornaam[0] . ' ' . $meta_achternaam[0]  . ' ' . $meta_email[0]);
    			wp_update_post(
    				array (
    					'post_title' => $combined_meta,
    				)
    			);
    			endwhile;
    		endif;
    		wp_reset_query();
    	}

    Hope it helps!

  7. scribu
    Member
    Plugin Author

    Posted 1 year ago #

    With the development version (1.6-alpha), you can use the 'p2p_candidate_title' filter to display extra meta information next to the title of the possible connections:

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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic