• I have excluded certain categories of posts from my blog so they never appear on my blog. However, in the blog chronological archive list that appears in the right side bar, the 6 excluded posts still appear as links and clicking on the link takes you to a list of the excluded posts.

    Can any one advise on how to remove these posts from the chronological archive?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Can you share a link to your site? What theme are you using?

    Thread Starter mattybrown1

    (@mattybrown1)

    It is ithemes builder with classen child theme. I have posted on their forum but I am not having much luck.

    Warning – The site belongs to a professional author who writes erotic fiction of the Fifty Shades of Grey genre! https://www.tessavalmur.com/blog/

    Moderator keesiemeijer

    (@keesiemeijer)

    Try excluding the categories with this in your theme’s functions.php:

    define("EXCLUDED_CATEGORIES", '25,55,57');
    
    add_filter( 'getarchives_join' , 'getarchives_join_filter');
    function getarchives_join_filter( $join ) {
    	global $wpdb;
    	return $join . " INNER JOIN {$wpdb->term_relationships} tr ON ($wpdb->posts.ID = tr.object_id) INNER JOIN {$wpdb->term_taxonomy} tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)";
    }
    
    add_filter( 'getarchives_where' , 'getarchives_where_filter');
    function getarchives_where_filter( $where ) {
    	global $wpdb;
    
    	$exclude = EXCLUDED_CATEGORIES; // category ids to exclude
    	return $where . " AND tt.taxonomy = 'category' AND tt.term_id NOT IN ($exclude)";
    
    	}
    
    // exclude categories on monthly archive pages
    function my_post_queries( $query ) {
    	// do not alter the query on wp-admin pages and only alter it if it's the main query
    	if (!is_admin() && $query->is_main_query()){
    
    		// alter the query for monthly archive pages
    		if(is_archive() && is_month()){
    			$query->set('category__not_in', array(EXCLUDED_CATEGORIES));
    		}
    	}
    }
    
    add_action( 'pre_get_posts', 'my_post_queries' );

    Change the category IDs you want to exclude in define("EXCLUDED_CATEGORIES", '25,55,57'); to the correct category ID’s

    Thread Starter mattybrown1

    (@mattybrown1)

    Thank you – that works well. The unwanted post categories have gone from the chronological archive list. But it has thrown up another problem which I’m not sure if is related.

    When you click on the October archives, a list of posts is displayed (there are currently two – post 1 and post 2) but only the body text of the post displays – no headings or details.

    Moderator keesiemeijer

    (@keesiemeijer)

    Did headings or details show up before you used my code?

    Can you paste and submit the full code of archive.php of your theme into a pastebin.com and post the link to it here? see the Forum Rules for posting code and using the pastebin.

    Thread Starter mattybrown1

    (@mattybrown1)

    I have just tried removing your code from the function.php and the same problem was still there for the ‘blog’ category posts (posts 1 and 2) but the ‘novels’ category posts were formatted as per the actual Novels page. (I have now replaced your code).

    Here is the code for the archive.php

    https://pastebin.com/PTQ5zmSa

    Thanks for you help.

    Moderator keesiemeijer

    (@keesiemeijer)

    This in your stylesheet style.css is hiding the titles:

    /*********************************************
        post/page titles
    *********************************************/
    .entry-title {
     display: none;
    }

    Remove it and the titles will show up.

    Thread Starter mattybrown1

    (@mattybrown1)

    Many thanks for you help.

    i also tried

    define("EXCLUDED_CATEGORIES", '25,55,57');
    
    add_filter( 'getarchives_join' , 'getarchives_join_filter');
    function getarchives_join_filter( $join ) {
    	global $wpdb;
    	return $join . " INNER JOIN {$wpdb->term_relationships} tr ON ($wpdb->posts.ID = tr.object_id) INNER JOIN {$wpdb->term_taxonomy} tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)";
    }
    
    add_filter( 'getarchives_where' , 'getarchives_where_filter');
    function getarchives_where_filter( $where ) {
    	global $wpdb;
    
    	$exclude = EXCLUDED_CATEGORIES; // category ids to exclude
    	return $where . " AND tt.taxonomy = 'category' AND tt.term_id NOT IN ($exclude)";
    
    	}
    
    // exclude categories on monthly archive pages
    function my_post_queries( $query ) {
    	// do not alter the query on wp-admin pages and only alter it if it's the main query
    	if (!is_admin() && $query->is_main_query()){
    
    		// alter the query for monthly archive pages
    		if(is_archive() && is_month()){
    			$query->set('category__not_in', array(EXCLUDED_CATEGORIES));
    		}
    	}
    }
    
    add_action( 'pre_get_posts', 'my_post_queries' );

    [Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    but this exclude only the first cat_id, for example if i have ‘1,3,8’ it will exclude only cat_id=1. How i can fix this?

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Remove Cetain Post Categories From Blog Sidebar Archive List’ is closed to new replies.