Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Found a great tutorial for excluding pages from search results here.

    The following function just needs adding to your theme’s functions.php file (create one if it doesn’t exist).

    <?php
    function mySearchFilter($query) {
    	if ($query->is_search) {
    		$query->set('post_type', 'post');
    	}
    	return $query;
    }
    
    add_filter('pre_get_posts','mySearchFilter');
    ?>

    Should be possible to adapt to exclude selected posts also but I’m a novice too and haven’t managed to figure it out yet.

    I’d be very interested to know how to combine the page exclude function above with the ability to exclude posts by tag. I’m guessing there’s a simple solution?

    There’s a great tutorial for excluding pages from search results here.

    In short, just add this to your theme’s functions.php file (or create the file if it doesn’t exist):

    <?php
    function mySearchFilter($query) {
    if ($query->is_search) {
    $query->set('post_type', 'post');
    }
    return $query;
    }
    
    add_filter('pre_get_posts','mySearchFilter');
    ?>

    It should be possible to adapt to exclude selected posts too but the author hasn’t gotten around to describing that yet.

    I’d be very interested to know how to combine the page exclude function above with the ability to exclude posts by tag. I’m guessing there’s a simple solution?

    There’s a great tutorial here.

    In short, just add this to your theme’s functions.php file (or create the file if it doesn’t exist):

    <?php
    function mySearchFilter($query) {
    if ($query->is_search) {
    $query->set('post_type', 'post');
    }
    return $query;
    }
    
    add_filter('pre_get_posts','mySearchFilter');
    ?>

    I’d be very interested to know how to combine the page exclude function above with the ability to exclude posts by tag. I’m guessing there’s a simple solution?

    This worked a treat: http://www.jepson.no/how-to-exclude-specific-tag-from-query_posts/

    get_var("SELECT term_ID FROM $wpdb->terms WHERE name='featured'");
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args=array(
       'tag__not_in' => array($tag),
       'paged'=>$paged,
       );
    query_posts($args);
    #
    ?>

    I dropped the first line:

    get_var("SELECT term_ID FROM $wpdb->terms WHERE name='featured'");

    Just pasted everything from “$paged” into the desired page above

    <?php if (have_posts()) : ?>

    Replace “$tag” with the tag ID number.

Viewing 4 replies - 1 through 4 (of 4 total)