List non-empty categories from a custom post type

This will end up being a little convoluted since the taxonomy just describes a relationship that may belong to any of the post types, so there’s not a direct data link for what you’re trying to fetch. But you could do something like this (untested), which could be a fairly heavy query if you’re doing … Read more

How to insert category to post via php?

Please try to use this function https://codex.wordpress.org/Function_Reference/wp_dropdown_categories wp_dropdown_categories() – Display the HTML dropdown list of categories <form id=”category-select” class=”category-select” action=”<?php echo esc_url( home_url( “https://wordpress.stackexchange.com/” ) ); ?>” method=”get”> <?php wp_dropdown_categories(); ?> <input type=”submit” name=”submit” value=”view” /> </form>

Show category in post page, that is in specific category

You should use get_the_category() instead of get_categories(). The get_the_category() function will return only categories assigned to the post, while get_categories() that you use returns all existing categories. Edit: To get categories assigned to post, but only those with the ancestor Food, you can use code: $args = [ ‘object_ids’ => get_the_ID(), // only categories assigned … Read more

Excluding specific category from custom theme functions

WP provides a number of conditionals. So, instead of this, which adds your JS and CSS to every URL on the site add_action( ‘wp_enqueue_scripts’, ‘my_scripts_method’ ); function my_scripts_method(){ wp_enqueue_script( ‘calc_fun’, ‘/wp-content/themes/flatsome-child/assets/js/calc.js’, array(), ‘1.6’); wp_enqueue_style( ‘calc_css’, ‘/wp-content/themes/flatsome-child/assets/css/calc.css’, true , 9.1 ); } You will want something like this, which only adds your JS and CSS to … Read more

Bulk assign posts to a category using SQL (MySQL)

OK, I think I found the answer myself… As stated in the post I linked to: wp_term_taxonomy – defines the taxonomy – either tag, category, or custom taxonomy term_taxonomy_id bigint(20) unsigned NOT NULL auto_increment, term_id bigint(20) unsigned NOT NULL default 0, taxonomy varchar(32) NOT NULL default ”, description longtext NOT NULL, parent bigint(20) unsigned NOT … Read more