Exclude parent category when getting category posts by slug

I wonder if a single typo is messing things up for you? Please try this: $args = array( ‘posts_per_page’ => ‘-1’, ‘orderby’ => ‘ID’, ‘order’ => ‘DESC’, ‘category_name’ => ‘documents’ ); $surveys = get_posts($args); where I replaced category-name with category_name. I know there is ways to exclude categories by ID but I need to use … Read more

post_categories array using variable

There’s an example here: http://codex.wordpress.org/Function_Reference/wp_insert_post // Create post object $my_post = array( ‘post_title’ => ‘My post’, ‘post_content’ => ‘This is my post.’, ‘post_status’ => ‘publish’, ‘post_author’ => 1, ‘post_category’ => array(8,39) ); // Insert the post into the database wp_insert_post( $my_post ); ‘post_category’ takes an array so you’d want to send it one. In your … Read more

How to remove the category from post slug

As @E pointed out, this is handled in Permalink Settings. To access these settings, look in the Admin menu on the left side of your screen. Under ‘Settings’ click on ‘Permalinks’ In ‘Permalinks’ you can see all of your various options for how to format the permalinks. It sounds like you want to use the … Read more

Change RSS format for specific categories

It certainly is! WordPress has filters called the_excerpt_rss and the_content_feed which filter the posts’ content and excerpts for the RSS feed. The filter is called in the loop, so you can use get_the_ID() and get_the_content() (and other loop functions) to fetch information about the post. add_filter( ‘the_excerpt_rss’, ‘wpse151603_rss_post_excerpt’ ); function wpse151603_rss_post_excerpt( $excerpt ) { $content … Read more

Anchor tag generates blank href attribute using echo esc_url( )

This is probably not the template for a category archive, but for a custom page template because of this: /* Template Name: Categories */ The query variable ‘cat’ is not set in pages. Move get_category_link( $id ); inside the foreach. <li><a href=”https://wordpress.stackexchange.com/questions/151716/<?php echo esc_url( get_category_link( $cat->term_id ) ); ?>”><?php echo $cat->name; ?></a></li>

Display subcategories selectbox on each category page

If you are referring to the categories from the post type post (the blog) then this would do the trick: For a drop-down: wp_dropdown_categories() For a list: wp_list_categories() child_of Only display categories that are children of the category identified by this parameter. There is no default for this parameter. <?php // Put the parent category … Read more

How to only show parent categories in sidebar

You can create a custom widget for that. // Widget Class ============================== class WPSE154979_Widget extends WP_Widget { function WPSE154979_Widget() { $widget_ops = array( ‘classname’ => ‘WPSE154979_custom_widget’, ‘description’ => __(‘Post Category Children\’s or Parent Categories’) ); $control_ops = array( ‘width’ => 200, ‘height’ => 400); $this->WP_Widget( ‘WPSE154979_custom’, ‘Custom Categories’, $widget_ops, $control_ops ); $this->alt_option_name=”WPSE154979_custom”; } function widget( … Read more

Conditional category & tag statement

I think your problem lies in is_category(). This conditional check if you are on a category page, not if a post belongs to a category. To check if a post belongs to a category, you should be using has_category So your conditional statement should be <?php if (has_category(‘Legal Libation Columns’) && has_tag(‘Legal Libation Columns’)): ?> … Read more

Exclude all subcategories in the_category (post)

There is no filter for the_category. All that the_category does is to echo get_the_category_list. Have a look at the function in wp-includes/category-template.php lines 273 – 275 273 function the_category( $separator=””, $parents=””, $post_id = false ) { 274 echo get_the_category_list( $separator, $parents, $post_id ); 275 } Personally I would say that the_category is incorrect for what … Read more