Now i´ve used the following snippet (https://github.com/simpliko/wpadverts-snippets/blob/master/custom-taxonomies/custom-taxonomies.php). Now it displays the new “advert_example” categories on the single page. But after click on the link it shows the standart wordpress blog list template and not the wp advert list style ( URL=/advert-example/categoryname/ – URL for advert-categeries=/adverts/?advert-category=categoryname). And how to display the new categories in the widget area?
Thanks!
Hi,
1. to display the advert-example taxonomy in a widget sidebar you can use some third party plugin like https://ww.wp.xz.cn/plugins/list-custom-taxonomy-widget/ the WPAdverts Categories widget can handle only the advert-category taxonomy.
2. similarly, only advert-category taxonomy can display the taxonomy pages using [adverts_list], for a custom taxonomy you would need to create a taxonomy-advert_example.php template file, please see the “Custom Taxonomy Template” section here https://wpadverts.com/documentation/child-themes-and-templates/ it is for the advert_category but the same should work for a custom taxonomy.
You should only need to remove the line
"category" => $wp_query->get_queried_object_id()
and instead above
remove_filter("the_content", "adverts_the_content");
add
add_filter( "adverts_list_query", function( $args ) {
global $wp_query;
if(!is_array($args["tax_query"])) {
$args["tax_query"] = array();
}
$args["tax_query"][] = array(
'taxonomy' => 'advert-example',
'field' => 'term_id',
'terms' => $wp_query->get_queried_object_id(),
);
return $args;
});
One note, i am not sure if your taxonomy name is advert_example or advert-example so based on that you would need to adjust the created file name and the line 'taxonomy' => 'advert-example',.
Hi,
thanks for the quick support! Everything works fine, but after adding
add_filter( "adverts_list_query", function( $args ) {
global $wp_query;
if(!is_array($args["tax_query"])) {
$args["tax_query"] = array();
}
$args["tax_query"][] = array(
'taxonomy' => 'advert-example',
'field' => 'term_id',
'terms' => $wp_query->get_queried_object_id(),
);
return $args;
});
to the functions.php only the new taxonomy is shown and every item in each advert_category is missing now.
-
This reply was modified 6 years, 10 months ago by
lenzsolution.
Since the beginning i had url´s for categories like – /adverts/?advert-category=catname – is that the right path?
1. i am not sure what do you mean by “only the new taxonomy is shown and every item in each advert_category is missing now”? also where do you add the code i pasted?
2. by default the path should be advert-category/catname, the one you are seeing will be usually enabled after installing Alt Term Links snippet https://github.com/simpliko/wpadverts-snippets/blob/master/alt-term-links/alt-term-links.php