Support

Account

Forum Replies Created

  • Over 2000 total News posts which is how I found this issue in the first place b/c I needed to be able to search on them rather than scroll through =P

  • That’s really strange. I added multiple post_types and changed to ‘all’ to test and it seems to be querying / grouping correctly.

    Multiple post types

  • You could try adding debug information into the method

    function acf_get_grouped_posts( $args ) {

    beginning on line 1547 in api/api-helpers.php

    The issue for me was the

    $posts = get_posts( $args );

    call on line 1583 was not using the “s” arg correctly. I debugged it by dumping out the $args var and trial / error.

  • Yep, I’m filtering on a specific post_type, but only 1, not multiple post_types.

  • functions.php is where you would add it.

    This solution is for a Post Object type specifically. If your field is a page_link you’d want to change the filter to

    add_filter( 'acf/fields/page_link/query', 'acf_post_object_custom_query', 10, 3 );

  • I think I see the issue.

    One line 1558 of api/api-helpers.php it is sorting the results using

    'orderby' => 'menu_order title',
    'order'   => 'ASC',

    For some reason, even though posts_per_page is set to 20, this was not respecting the ‘s’ query arg and returning 20 posts ordered alphabetically. The solution I found was to add a filter on ‘acf/fields/post_object/query’ and set the ‘orderby’ arg to null. This will override the default ‘menu_order title’ argument, and worked for me.

    function acf_post_object_custom_query( $args, $field, $post_id ) 
    {
        $args['orderby'] = null;
        return $args;
    }
    
    add_filter( 'acf/fields/post_object/query', 'acf_post_object_custom_query', 10, 3 );

    These were my results searching for ‘traffic’.
    Before:
    Searching for traffic before filter

    After:
    Searching for traffic after filter

    If there is a better solution, please post it.

  • Since this was only setting it to null and not actually deleting the row I wanted a better solution. I came up with this which essentially gets the position of the field you want and moves every row after it back one and then removes the last row of the repeater thus completely deleting that value.
    https://gist.github.com/aaronjheinen/53ff4a44362927711d37

  • This certainly can work but I’d like to keep the content area as-is for excerpt functionality. I did find a solution but it looks like it searches all post_meta, so it’s not something that can specifically be set.

    I would like to see a “Searchable” Boolean added to field types.

    // Search on custom fields
    function custom_search_join ($join){
        global $pagenow, $wpdb;
        $types = ['course'];
        // I want the filter only when performing a search on edit page of Custom Post Type in $types array
        if ( is_admin() && $pagenow=='edit.php' && in_array( $_GET['post_type'], $types ) && isset( $_GET['s'] ) ) {    
            $join .='LEFT JOIN '.$wpdb->postmeta. ' ON '. $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
        }
        return $join;
    }
    add_filter('posts_join', 'custom_search_join' );
    function custom_search_where( $where ){
        global $pagenow, $wpdb;
        $types = ['course'];
        // I want the filter only when performing a search on edit page of Custom Post Type in $types array
        if ( is_admin() && $pagenow=='edit.php' && in_array( $_GET['post_type'], $types ) && isset( $_GET['s'] ) ) {
            $where = preg_replace(
           "/\(\s*".$wpdb->posts.".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
           "(".$wpdb->posts.".post_title LIKE $1) OR (".$wpdb->postmeta.".meta_value LIKE $1)", $where );
        }
        return $where;
    }
    add_filter( 'posts_where', 'custom_search_where' );
    function custom_search_distinct( $where ){
        global $pagenow, $wpdb;
        $types = ['course'];
        if ( is_admin() && $pagenow=='edit.php' && in_array( $_GET['post_type'], $types ) && isset( $_GET['s'] ) ) {
        return "DISTINCT";
    
        }
        return $where;
    }
    add_filter( 'posts_distinct', 'custom_search_distinct' );
Viewing 9 posts - 1 through 9 (of 9 total)