Filter Posts by Excluding Categories

You can hook into the load-edit.php action to modify how wp-admin lists pages. Add this to your functions.php: <?php add_action( ‘load-edit.php’, ‘namespace_modify_admin_list’ ); function namespace_modify_admin_list() { global $typenow; if ( ‘post’ !== $typenow ) return; add_action( ‘pre_get_posts’, ‘namespace_modify_admin_list_posts’ ); } function namespace_modify_admin_list_posts( $query ) { /** * Modify query here to change how posts are … Read more

How to exclude a directory from WordPress permalinks in a Multisite environment?

This “exception” would only be required if you are requesting virtual URLs within /folderToExclude, as opposed to physical files. Any requests to physical directories and files are naturally excluded by the standard WordPress directives. RewriteCond %{REQUEST_URI} !^/(folderToExclude/.*)$ # add a trailing slash to /wp-admin RewriteRule ^wp-admin$ wp-admin/ [R=301,L] This condition (RewriteCond directive) won’t do anything … Read more

Query Ignoring ‘exclude’ Parameter?

WP_Query does not support an exclude argument. To exclude a post by ID, use post__not_in and pass it an array of IDs. Using your code above, your arguments could look like this: $args2 = array( ‘posts_per_page’ => 3, ‘post_type’ => ‘post’, ‘ignore_sticky_posts’ => 1, ‘orderby’ => ‘rand’, ‘tag__in’ => array( $first_tag, $second_tag ), ‘post__not_in’ => … Read more

How to exclude shortcode from specific page IDs if it’s set to global

Please try this and let me know the result function my_shortcode_to_a_post( $content ) { global $post; $disabled_post_ids = array(’20’, ’31’, ’35’); $disabled_tag_ids = array(‘5′, ’19’, ’25’); $current_post_id = get_the_ID(); // try setting it to $post->ID; if it doesn’t work for some reason if(in_array($current_post_id, $disabled_post_ids)) { return $content; } $current_post_tags = get_the_tags($current_post_id); if($current_post_tags){ $tags_arr = array(); … Read more

Exclude One Category and its Subcategories using WP_LIST_FILTER

I am answering a question after like 6 months, so I expect the quality of my answer not upto WPSE standards and hence would love feedback from other experience WPSE gurus. Add the following function to your functions.php function filter_category_list_by_slug( $slug, $categories ) { $excluded_parent = get_category_by_slug( $slug ); $excluded_cats = get_categories( array( ‘child_of’ => … Read more

Exclude a specific tag from the get_the_tags list

$tags = get_the_tags( $post->ID ); $separator=” “; $output=””; if($tags){ echo ‘<div class=”entry-tags”>’; echo “<p><span>” . __(‘Tags’, ‘tracks’) . “</span>”; foreach($tags as $tag) { // dpm($tag) here by uncomment you can check tag slug which you want to exclude if($tag->slug != “yourtag”){ // replace yourtag with you required tag name $output .= ‘<a href=”‘.get_tag_link( $tag->term_id ).'” … Read more

Do not allow to search certain words

Try this in your functions.php, and change news for whatever you want to be blocked in your site. add_action(‘wp’, ‘check_search’); function check_search() { global $wp_query; if (!$s = get_search_query()) return false; if (preg_match(‘/news/’, $s)) { $wp_query->set_404(); status_header(404); get_template_part(404); exit(); } } Hope it helps.

Dynamically excluding current page id

In your code, if $post_id were, say, 99, this: query_posts(“showposts=4&post_type=page&post_parent=168&orderby=rand&exclude=”. $post_id .””); would result in this being passed to query posts: query_posts(“showposts=4&post_type=page&post_parent=168&orderby=rand&exclude=”. 99 .””); so, your issue here is ‘. 99 .’ isn’t a valid value for exclude. That said, query_posts should only be used to alter the main loop in a template. if you … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)