How could I know all the categories from post?

Your problem lies in this piece of code $categoriaActual = get_the_category($post->ID); $idCategoriaActual = $categoriaActual[0]->term_id; The first line gets the categories that belongs to the post in an array, that is fine (Just one note, when inside the loop, you don’t need to pass the post ID, that is done by default). Your second line of … Read more

Change every post background based on category

The body_class() is what controls those classes, and does not include the category in single posts. That is why the CSS doesn’t work once you click through to a post. I did find a function that may help, though. Try placing this in your functions.php. This will add the current post’s category back to the … Read more

Randomly load categories with latest post

Never ever use query_posts, it creates an endless amount of issues as it breaks the main query object on which so many build in functions, custom functions and plugin rely on. It is pure evil and you should avoid it as such as well. For custom queries, use WP_Query or get_posts, if you simply need … Read more

Exclude categories from wp_list_categories by category slug

I would suggest a cleaner approach would be to implement an exclude_slugs argument for the function, then you can just use the following in your template code: wp_list_categories([ ‘exclude_slugs’ => [ ‘fp-feature’, ‘fp-aside-feature’ ], // Other arguments ]); Here’s the filter, pop it in your functions.php: function wpse_217847_list_terms_exclusions( $query, $args ) { if ( ! … Read more

Create category post shortcode

Needs a complete rewrite… add_shortcode( ‘categorypost’, ‘cat_post’ ); function cat_post( $atts ) { // attributes for shortcode if ( isset( $atts[‘cat’] ) ) {$cats = $atts[‘cat’];} else {return;} if ( isset( $atts[‘posts_per_page’] ) ) {$posts_per_page = $atts[‘posts_per_page’];} else {$posts_per_page = -1;} // get the category posts $category = get_category_by_slug( $cats ); if ( !is_object( $category … Read more

Targeting Parent Category Pages

You can do this using custom template and template_include filter. category-parent.php and category-sub.php both are not required. One can be category.php for parent categories and for child categories, you can use custom-category-child.php as category-sub.php is reserved for default hierarchy. First create a template file in theme custom-category-child.php Then add this code to your theme functions.php … Read more

Keyword search in multiple categories

let’s start by defining an HTML search form: <form method=”get” action=”<?php bloginfo(‘url’); ?>”> <fieldset> <input type=”text” name=”s” value=”” placeholder=”search&hellip;” maxlength=”50″ required=”required” /> <p>Refine search to posts containing chosen tags:</p> <?php // generate list of categories $tags = get_categories(); foreach ($tags as $tag) { echo ‘<label>’, ‘<input type=”checkbox” name=”taglist[]” value=”‘, $tag->slug, ‘” /> ‘, $tag->name, “</label>\n”; … Read more

Get sort order of product categories

Answering for posterity, since I ran into the same issue and this thread is the closest thing I found to what I was looking for. The solution turned out to be quite simple. If you don’t specify ‘orderby’ in your arguments, the default sort order will be used (the category order in the Woo admin). … Read more