Site icon Hip-Hop Website Design and Development

Methods to create/modfiy WP_Query to look in submit title OR customized discipline?

I would like to change or create a WP_Query that may seek for a search time period in each the submit title OR a customized discipline (referred to as ‘my_field’).

I’ve been studying and attempting for hours, however I’m proper again to this code (under) which, alas, solely searches in ‘my_field’ and doesn’t take the post_title under consideration.

operate my_pre_get_posts_2( $question ) {
if ( is_admin() && $query->is_main_query() && $query->question['post_type'] === 'submit' && isset($query->question['s']) ) {

    $search_word = $query->question['s'];

    $args = array(
        //'s' => $search_word, //If I embrace this line, the WP question appears to AND post_title and my_field. If I remark out this line, the WP question solely searches in my_field
        'post_type' => 'submit',
        'meta_query' => array(
            'relation' => 'OR',
            array(
                'key' => 'my_field',
                'worth' => $search_word,
                'evaluate' => 'IN'
            ),
            array(
                'key' => 'post_title',
                'worth' => $search_word,
                'evaluate' => 'IN',
            )
        )
    );

    //$question = new WP_Query( $args ); //Want to change the present WP_Query
    $query->init();
    $query->parse_query($args);
}

}
add_action( 'pre_get_posts', 'my_pre_get_posts_2' );

The explanation I must do it’s because I would like to change the behaviour of the the ‘Search Posts’ button within the ‘All Posts’ (admin) web page in order that regardless of the admin person searches for, it would return the posts which have an identical submit title OR my_field worth.