Abdul Ali
Abdul Ali

Reputation: 1937

wordpress Custom search page returning all post type

have written a custom wordpress search template and wish to retrieve only 'post' type posts and not any page or any custom post type.

The issue is that the query is returning all posts type (and pages) .. following is the query arguments .

$pageContent = new WP_query();
$pageContent->query(array('s'=> $query, 'posts_per_page' => -1, 'post_type' => 'post'));

Another issue (not very important at the moment), the next_posts_link() and previous_posts_link() do not seem to show any link for pagination as well.

Any help appreciated.

Upvotes: 1

Views: 2052

Answers (1)

Abdul Ali
Abdul Ali

Reputation: 1937

Found a solution by adding the above mentioned filter and doing the following:

add_action('pre_get_posts','SearchFilter');

function SearchFilter($query) {
        $query->set('post_type', 'post');
        return $query;
    }

Thank you for all the time :) ..

Upvotes: 2

Related Questions