skip to Main Content

I really don’t know what’s the issue. I think my code is OK but the output is wrong. I don’t know anything about WordPress, please help me.

elseif ($_GET['search']) {
    $args = array(
        'post_type' => 'head_to_toe_videos',
        'post_status' => 'publish',
        'meta_query' => array(
            array(
                'key' => 'post_title',
                'value' => $_GET['search'],
                'compare' => 'LIKE',
            )
        ),
        'posts_per_page' => 12,
    );
}

2

Answers


  1. Your query is correct but need to execute you query like this:

    $the_query = new WP_Query( $args );
    $result = $the_query->get_results();
    
    echo "<pre>"; print_r($result); exit;
    
    Login or Signup to reply.
  2. Try the below code your problem will solve.

        elseif ($_GET['search'] != '') {
        $args = array(
            'post_type' => 'head_to_toe_videos',
            'post_status' => 'publish',
            'meta_key'   => 'post_title',
            'meta_query' => array(
                array(
                    'key' => 'post_title',
                    'value' => $_GET['search'],
                    'compare' => 'LIKE',
                )
            ),
            'posts_per_page' => 12,
        );
        
        $result = new WP_Query( $args );
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search