Exclude the category in WordPress

If retrieve_cat_data_sp is the function from this question then that returns categories except the ones given in the argument: $cat_lists = retrieve_cat_data_sp(’81’); It essentially a wrapper for get_categories. So to exclude multiple Ids $cat_lists = retrieve_cat_data_sp(‘81,82’); If you want to exclude 81 as well as those IDs listed in get_option(‘bn_exclude_home_lists’) then, assuming that option returns … Read more

Shortcode to display all the post from a category in a page

Try this… <?php function list_post(){ //or you can use the cat id here, check the codex for WP_Query $q = new WP_Query(array(‘category_name’ => ‘<cat slug here>’)); if($q->have_posts()): while($q->have_posts()):the_post(); the_title(); endwhile; else: echo “No posts found!”; endif; wp_reset_postdata(); } add_shortcode(‘list_post’, ‘list_post’); ?>

Subcategory is displayed before Parent Category

This is a tricky and interesting one. It would be pretty easy to write hardcoded orders for a whitelist of categories, but a true ordering algorithm – which will handle an arbitrary number of categories, and an arbitrary tree depth – requires recursion. What follows probably is not the most efficient solution possible, but it … Read more

Detect category choice for posts with multiple categories

Use: get_query_var(‘category-name’); Which will give you: example.com/category/subcategory/my_post Which you can then put into any queries you make under category-name. You can see this in action using the Monkeyman rewrite analyser plugin, by entering one of the URLs for a post and seeing the query variables it generates using those rules

Update custom category fields front-end

the function wp_insert_term returns the newly created term id (or WP_Error on error), so once your create your term you need to store it’s ID and then you can save the “extra fields” using get_option, update_option something like: if($_SERVER[‘REQUEST_METHOD’] == “POST”) { $clientName = $_POST[“clientName”]; $term_id = $_POST[“clientName”]; $clientKeywords = $_POST[“clientKeywords”]; $clientSlug = $_POST[“clientSlug”]; $parent=””; … Read more