• urbanor

    (@urbanor)


    I have a 2.3 WordPress site that I’d like to upgrade to 2.5, but there’s only one issue – I don’t want pages included in the search (one of 2.5’s new features).

    Anyone know if there’s a way to only search posts with 2.5?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter urbanor

    (@urbanor)

    bump!

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Include a hidden input field with your search form like this one:
    <input type="hidden" name="post_type" value="post" />

    Should work, I think.

    Thread Starter urbanor

    (@urbanor)

    Otto42, thanks for the reply and that seems like a logical fix, but I had no luck. After adding in that hidden field, the search still returns pages and posts.

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Hrm… I thought that would work. Oh well, I’ll have another look at the code.

    Looking closer at it, I can’t see why that doesn’t work. Are you sure you put it in the form properly? Got a link so I can see your search results?

    Thread Starter urbanor

    (@urbanor)

    I’m sure the hidden field is in the form properly. With a get method on the form the URL output is like this http://*.com/?post_type=post&s=querytext

    I can send you the URL, but it’s on a dev site that I’d rather not post publicly. Can I email you?

    Thread Starter urbanor

    (@urbanor)

    …Guess not. Well, anyway, the hidden field post_type set to post *does not* work. Try it for yourself. WordPress bug?

    Thread Starter urbanor

    (@urbanor)

    kmogvideo

    (@kmogvideo)

    Are there any updates on this issue? I too would like the search bar to display only posts.

    kmogvideo

    (@kmogvideo)

    Someone gave me a great solution. If you use the ‘Search Everything‘ plug-in, you can enter your page id’s to be excluded from the search. Worked great for me, may not be ideal for people with 100+ pages.

    btsoom

    (@btsoom)

    I had this problem myself since I mainly use WP as a CMS and wrote this a small, rudimentary plugin:

    add_filter('posts_where', 'SearchNoPages');

    This adds a filter for the SearchNoPages function below to the posts_where hook.

    function SearchNoPages($where)
    {
    	global $wp_query;
    	if(!empty($wp_query->query_vars['s']))
    	{
    
    		$where .= ' AND (in_posts.post_type=\'post\')';
    	}
    	return $where;
    }

    Now this just adds the post_type=’post’ to the where clause so that posts with post_type=’page’ are excluded.

    Put this together in a php file in and save it in your plugins folder (see the documentation on how to make plugins)

    Hope this helps.

    btsoom

    (@btsoom)

    better remove in_posts. since you probably use another prefix

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘2.5 Search Posts Only?’ is closed to new replies.