Need to pull parent category and slug – only pulling daughter category

There are functions for retrieving a term/category link (i.e. URL to the term archive page) and in the case of the default category taxonomy, you can use get_category_link(): <a href=”https://wordpress.stackexchange.com/questions/361461/<?php echo esc_url( get_category_link( $category[0] ) ); ?>”><?php echo $category[0]->name; ?></a> For custom taxonomies, you’d use get_term_link().

Set post categories to include parents when setting child category

This will check to see if there is a hierarchy and set all parent categories as checked. This function assumes that if there’s multiple categories already set, then don’t do the function, since the categories would be correct if multiples are set. function set_product_parent_categories( $post_id ) { $category = wp_get_post_terms( $post_id, ‘product_cat’ ); // If … Read more

Get categories from save_post hook

After doing much more search… it looks like the save_post hook does not run after the post categories are updated so it will only show the categories that the post had before the update (or no categories for new posts). I found that I need to use this hook and then everything inside my function … Read more

How do I create a way for users to assign categories to a post from the frontend of the website?

just remove this line update_term_cache($affected_terms); and it works perfectly <?php /* Plugin Name: WPSE Crowded Cats Plugin URI: http://wordpress.stackexchange.com/questions/43419/how-do-i-create-a-way-for-users-to-assign-categories-to-a-post-from-the-frontend Description: Allow visitors to change categories of posts. Ready to use with custom taxonomies and post types. Version: 0.1 Author: WPSE Author URI: http://wordpress.stackexchange.com/users/2110/maugly License: GPL2 */ add_action(‘plugins_loaded’,’wpse_init_crowd_cats_class’); function wpse_init_crowd_cats_class(){ new WPSECrowdCatsClass(); } class WPSECrowdCatsClass { … Read more

How to create button to direct to certain category

If you know the id of the category, this is how you can output a link to category. <a href=”<?php echo get_category_link( $idofcategory ); ?>” title=”Category Name”>Category Name</a> Check this : https://developer.wordpress.org/reference/functions/get_category_link/ Above page also shows how you can get the category link from category name, in case if you don’t know id of the … Read more

Broken category pagination

Try creating a new instance of WP_Query and at the end use wp_reset_query(); like this: <?php $my_query = new WP_Query(); $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $my_query->query(‘cat=”. $id .”&posts_per_page=4&paged=’.$paged); while ($my_query->have_posts()) : $my_query->the_post(); ?> <?php get_the_content() ?> <?php endwhile; ?> <?php if ( $my_query->max_num_pages > 1 ) : ?> <?php previous_posts_link( __( ‘Previous’, ‘themename’ … Read more

Check child/parent categories if exists

You can get the current posts category outside the loop by using the get_the_category function. http://codex.wordpress.org/Function_Reference/get_the_category When you have the actual category ( however you got it) you can use get_categories, specifically the ‘child_of’ parameter and pass it the parent cat ID. http://codex.wordpress.org/Function_Reference/get_categories Also have a look at wp_list_catagories, http://codex.wordpress.org/Template_Tags/wp_list_categories#Display_or_Hide_the_List_Heading where you can do something … Read more