New answers tagged

0

There are several robots.txt generators online. Here is one of my favorites. After you've generated your file, I highly recommend testing it with Google's Webmaster Tools tester. I've done this for dozens of sites, and never have a problem. Just remember the following: Most Wordpress sites treat categories as if they're folders/directories. So, to ...


0

You can use the same code, you just have to find the id of your category by slug. Yo can do this by adding : $idObj = get_category_by_slug('category-slug'); $id = $idObj->term_id; And then put $id in your excluding array. the function is documented here : wordpress documentation


0

I know that this question is old, but I found another solution that seems to be simpler than a custom walker, and wanted to post it for anyone else looking for a solution. You can use the category_css_class filter. add_filter( 'category_css_class', 'add_category_slug_as_class', 10, 4); public static function add_category_slug_as_class($css_classes, $...


0

Here's something I made. The explanations are in the code comments. I get the categories, loop through them if they have one product assigned to them I get it and its permalink. // Gets all product categories that // have products assigned to them $product_cats = get_terms( array( 'taxonomy' => 'product_cat', 'hide_empty' => true, ));...


0

Ahh ha! Have figured out how to do this. Here's the code for future people who are looking for the same thing: function get_category_tags($args) { global $wpdb; $tags = $wpdb->get_results(" SELECT DISTINCT terms2.term_id as tag_id, terms2.name as tag_name, terms2.slug as tag_slug, null as tag_link FROM wp_posts as p1 ...


0

function product_terms_by_cat() { $terms = get_terms ( array ( 'taxonomy' => 'product_category', 'hide_empty' => false) ); foreach ( $terms as $term ) { echo $term->name; } } add_shortcode('product_terms_by_cat', 'product_terms_by_cat');


1

Maybe you want to try adding products to subcategory, but not showing them on main categories. Then when user filters and goes to subc, you show products. Link


1

Try to add the following code in functions.php of your theme and it should do the job. function dcg_tidy_rss_categories( $the_list ) { $categories = get_the_category(); $tags = get_the_tags(); if ( ! empty( $categories ) ) { foreach ($categories as $category) { // remove the following line if you don't want Categories to ...


0

Shibi's answer no longer works properly when saving posts with the new block editor (Gutenberg) because the call to set the post terms (which sets the categories) now occurs after the save_post action is run. Instead, the function in the accepted answer checks only the old terms, meaning only the second time after a post is saved with the default category ...


0

Right now you are looping the default WP_Query. Better to define the exact query to fetch the exact posts you want. Here is a link to the complete guide of how to use it, and how to use taxonomies: https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters


0

If you are building your own taxonomy you can set the capabilities when registering the taxonomy. For example... <?php register_taxonomy( 'members_tax', 'post', array( 'label' => __( 'Members' ), 'hierarchical' => true, 'rewrite' => array( 'slug' => '...


-1

if((get_the_category_list() !== 'Uncategorized')){ the_category(); }


0

If there is a long list of categories, pagination breaks the hierarchy causing the issue OP is having. This is a very long-standing issue. A plugin has been posted there, that disables pagination, so hierarchy is kept intact. Reported to work well up to 2500 categories & subcategories (after that it's probably a server timeout issue). Or you can use ...


0

In addition to @tobidude's great solution, a complete exemple: Create the functions function sortCategories($categories) { // Sorting the category usort($categories, "cmpCategories"); return $categories; } function cmpCategories($category_1,$category_2) { // Sort function foreach(get_categories(array("parent" => $category_1->cat_ID)) AS $...


0

You can use the following code in single.php loop to display nex/pre links in same category <?php get_template_part( 'content', get_post_format() ); // Previous/next post navigation. previous_post_link('%link', 'Before', true ); next_post_link( '%link', 'Next', true ); ?>


0

Concerning the second part of your question (building the links): I had a similar problem with combining tags and categories for a menu on a Woocommerce page. I ended up utilizing wp_list_categories and made use of the output filter of that function. Filtering the URLs with that filter (credit: https://stackoverflow.com/questions/5809774/manipulate-a-url-...


0

Old question but top result on Google for me. I couldn't quickly find a breadcrumb categorization, supporting multiple categories, so I created one and wrapped it in a ul for easy styling: // breadcrumb categorization $cats = wp_get_post_categories( get_the_ID() ); //post id foreach($cats as $c) { $ancestors = array_merge( array_reverse( get_ancestors(...


0

try this here i get category on three page function tpa_exclude_technology_cat( $query ) { if ( !$query->get_queried_object_id('8') || !$query->get_queried_object_id('Berries page id here') || !$query->get_queried_object_id('Stone Fruits page id here')) { // "Fruits"-page has id of 8 $query->set( 'cat', '-3' ); // "Fruits-Category" has id of ...


1

You want display posts of a given type ({post_type}) from category ({term}) and structure of link should looks like this: {post_type} / category / {term} To avoid collisions with links to pages and "blog" posts, expression can not start with ([^/]+), but should contain slug of post type entered explicitly. This means a separate rule for each custom post ...


1

To account for variations, I'd suggest using $product->get_category_ids() and checking if your category is in there: function wcs_custom_get_availability( $availability, $_product ) { $workshops_category = get_term_by( 'slug', 'workshops', 'product_cat' ); $product_category_ids = $_product->get_category_ids(); if ( ! in_array( $...


0

It depends on the Wordpress theme you're using. If you can find out what html class the category/post meta is under using Inspect Element, it will be easy to hide it via CSS. Otherwise you will need to find where the 'Post Meta Data' is being added in PHP inside your theme and remove it. For now you can try and paste the following code inside your style.css ...


0

I didn't find the cause. But I was able to hack a solution into functions.php: add_action("wp", "disable_duplicate_categories"); function disable_duplicate_categories() { if (is_category()) { $urlParts = explode('/', $_SERVER["REQUEST_URI"]); if ($urlParts[1] !== 'category') { array_splice($urlParts, 1, 0, 'category'); ...


Top 50 recent answers are included