Skip to main content
edited tags
Link
kaiser
  • 50.8k
  • 27
  • 150
  • 244

I would like to search in custom_postcustom_post by title and by the ACF fields.

So, iI used the WP_Query WordpressWP_Query WordPress function but iI can't filter by the title, just by the filters.

When I submit my form, iI have this kind of URL: http://site.com/?s=titre&filter1=condition1&filter2=condition2&filter3=condition3

http://example.com/?s=titre&filter1=condition1&filter2=condition2&filter3=condition3

My code:

$title = $_GET['s'];
$args = array(
    'pagename' => $title,
    'numberposts' => -1,
    'post_type' => 'my_custom_post',
    'meta_query' => array(
        array(
            'key' => 'filter_1',
            'value' => $_GET['condition_1']
        ),
        array(
            'key' => 'filter_2',
            'value' => $_GET['condition_2']
        ),
        array(
            'key' => 'filter_3',
            'value' => $_GET['condition_3']
        )
    )
);
$the_query = new WP_Query($args);

Do you have any ideasidea to include the title in the search ?

Thank you !

I would like to search in custom_post by title and by the ACF fields.

So, i used the WP_Query Wordpress function but i can't filter by the title, just by the filters.

When I submit my form, i have this kind of URL: http://site.com/?s=titre&filter1=condition1&filter2=condition2&filter3=condition3

My code:

$title = $_GET['s'];
$args = array(
    'pagename' => $title,
    'numberposts' => -1,
    'post_type' => 'my_custom_post',
    'meta_query' => array(
        array(
            'key' => 'filter_1',
            'value' => $_GET['condition_1']
        ),
        array(
            'key' => 'filter_2',
            'value' => $_GET['condition_2']
        ),
        array(
            'key' => 'filter_3',
            'value' => $_GET['condition_3']
        )
    )
);
$the_query = new WP_Query($args);

Do you have any ideas to include the title in the search ?

Thank you !

I would like to search in custom_post by title and by the ACF fields.

So, I used the WP_Query WordPress function but I can't filter by the title, just by the filters.

When I submit my form, I have this kind of URL:

http://example.com/?s=titre&filter1=condition1&filter2=condition2&filter3=condition3

My code:

$title = $_GET['s'];
$args = array(
    'pagename' => $title,
    'numberposts' => -1,
    'post_type' => 'my_custom_post',
    'meta_query' => array(
        array(
            'key' => 'filter_1',
            'value' => $_GET['condition_1']
        ),
        array(
            'key' => 'filter_2',
            'value' => $_GET['condition_2']
        ),
        array(
            'key' => 'filter_3',
            'value' => $_GET['condition_3']
        )
    )
);
$the_query = new WP_Query($args);

Do you have any idea to include the title in the search ?

Source Link

Search with filters and title

I would like to search in custom_post by title and by the ACF fields.

So, i used the WP_Query Wordpress function but i can't filter by the title, just by the filters.

When I submit my form, i have this kind of URL: http://site.com/?s=titre&filter1=condition1&filter2=condition2&filter3=condition3

My code:

$title = $_GET['s'];
$args = array(
    'pagename' => $title,
    'numberposts' => -1,
    'post_type' => 'my_custom_post',
    'meta_query' => array(
        array(
            'key' => 'filter_1',
            'value' => $_GET['condition_1']
        ),
        array(
            'key' => 'filter_2',
            'value' => $_GET['condition_2']
        ),
        array(
            'key' => 'filter_3',
            'value' => $_GET['condition_3']
        )
    )
);
$the_query = new WP_Query($args);

Do you have any ideas to include the title in the search ?

Thank you !