Support

Account

Home Forums Backend Issues (wp-admin) Relationship Field: search by ID

Solving

Relationship Field: search by ID

  • Hi,

    I have a relationship field listing all the pages of our website. We have more than 5,000 pages, and when we search using the lookahead field at the top of the relationship box, we often get many pages that are not relevant to the search string we type. It would be great if we could extend the field to search by post/page ID. I’ve tried to hook into this filter

    acf/fields/relationship/query/name=access_control_settings_pages

    and I’ve tried various ways to tweak the $args parameter, but I can’t seem to be able to find the right way. This is what I have:

    public static function add_page_id_to_search( $args, $field, $post_id ) {
    		if ( !empty( $args[ 's' ] ) ) {
    			if ( intval( $args[ 's' ] ) != 0 ) {
    				$args[ 'page_id' ] = array( intval( $args[ 's' ] ) );	
    			} 
    		}
    
    	  	return $args;
    	}

    Could you please point me into the right direction on how to solve this issue?

  • I’m not sure what issue you’re trying to solve. Can you give a better explanation of what you’re trying to do? I understand what filter you’re trying to use but your first paragraph does not make any sense to me.

  • The first paragraph makes complete sense to me. I’m having the exact same issue. I need to search by post_id or post_title instead of the whole post content. Currently the search returns a whole lot of irrelevant results. Judging by the number of issues in the forum talking about relationship search being broken I think ACF should focus on fixing this asap.

  • Searching by anything other than post title/content in WP is difficult. ACF basically uses the built in WP admin search the same way that WP uses it when, for example you search for posts on the list of posts. You can’t just add the post ID into the s argument and expect this to work.

    I recently replied to another similar topic and this is what I found then https://wordpress.stackexchange.com/questions/99849/search-that-will-look-in-custom-field-post-title-and-post-content

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Relationship Field: search by ID’ is closed to new replies.