New answers tagged

0

this code works on the single-product.php (single product page). I had build the code following your diagram Island (parent) province (child) City (sub-child) this means supposing the cities are a 3rd level category. global $post; $cats = get_the_terms( $post->ID, 'product_cat' ); $count = 0; foreach ($cats as $parent){ if($parent->parent == 0){ ...


0

Once you have found the right .htaccess file in the document root (ie. inside the public_html directory) then these redirect directives need to go at the top of the .htaccess file, before the existing WordPress directives. ie. Before the # BEGIN WordPress section. You do not need to repeat the RewriteEngine or RewriteBase directives. (The RewriteBase ...


0

The documentation for the wp_list_categories filter says that it: Filters the HTML output of a taxonomy list. So it filters the final HTML, not the args, but you're returning $args, which means that the final HTML is replaced with the args array. That's why you're seeing "Array". To filter the args for the categories list in the Categories widget,...


0

Check if this code helps you $cats = $product->get_categories(); $cities = []; foreach ($cats as $key => $cat): if ($cat->parent == 0): foreach ($cats as $key => $cat2): if ($cat2->parent == $cat->term_id): foreach ($cats as $key => $cat3): if ($cat3->parent == $cat2->...


0

only getting deep in the code, but this should give the categories associated with the product $sub_child = $product->get_categories(); foreach($sub_child as $a){ echo $a; } if this gives the sub-child, child and parents, then must be built some kind of filter to show only the sub-child. to the sub-districts I imagine something like: $district = $...


0

get_categories() uses get_terms() so the array argument you can pass it will be the same. From the documentation the array can have a property hide_empty, by default its true. I'm guessing that those categories have no posts attached to it, if that is the case you will need to set it to false. The code would be like this. get_categories([ 'child_of' =&...


2

You can fix that by setting the second parameter for single_cat_title() to false, which then returns the title instead of echoing it (before the <title> tag), like so: $title = sprintf('%1$s Race Calendar', single_cat_title( '', false ) );


1

Yes you can! Just select the primary category of the post. I am sorry that this screenshot is german, but it is pretty self-explaining. Here we have a main group "Party" with a subgroup "Rezepte". We can set the url to only "/party" by selecting that category as a new main. The screenshot is taken from WordPress 5.8 Also make ...


0

You can use this following code snippet in any theme file or you can also create a new page template. Before using this code, don’t forget to replace category IDs that you want to fetch post from. <?php // display random post from specific categories $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'cat' => '2, 6, ...


1

As Howard E said, without knowing more about what and how you want to reorder it's difficult to give you useful advice. Here's a good breakdown of the options and, here are some places to start. If you want an array of posts to order your own way, you can use the native function get_posts() in order to create an array of posts based on selected arguments. ...


0

If you have a need to build up an actual structure of terms, this might be a useful method for you: /** * Recursively sort an array of taxonomy terms hierarchically. Child categories will be * placed under a 'children' member of their parent term. * @param Array $cats taxonomy term objects to sort * @param Array $into result array to put them ...


0

After messing around with the code I found a solution to add a categorie label straight under the sales-tag on a product archive page. //Tonen van Nieuw-label op archive page function show_new_label(){ //Check all the categories of taxonomy product_cat $argsTax = array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'all'); $terms = ...


0

how I can get the categories from the same global search You can add a taxonomy attribute to your shortcode and then pass the value to get_query_terms_list(), like so: add_shortcode( 'bd_terms_list', 'bd_terms_list_custom_callback'); function bd_terms_list_custom_callback( $args ){ $atts = shortcode_atts( array( // list of default attributes '...


2

How to obtain the recent posts without their content? The same way you would any other post, just don't use the post content. Not fetching the post content will not improve performance, and may actually hurt performance. This is because WordPress would need to make an additional query if it needed the post content. When you query a post, WP primes temporary ...


Top 50 recent answers are included