Hi everyone,
(I already contacted support, but I thought maybe someone here in the community has had a similar problem and can lend a hand as well )
I’m struggling with the query block and taxonomy terms for custom taxonomies. I’ve registered a couple custom taxonomies with the default wordpress post type. Usually I would’ve registered them using ACF but the custom taxonomies come from a plugin called WP Recipe Maker and they’re not easily accessible by default. Therefore I had to register them manually using the following PHP snippet:
function register_recipe_taxonomies_for_parent_post() {
// Only run this on the 'recipe' post type
if ($post_type !== 'post') {
return;
}
// Add the 'wprm_course' and 'wprm_cuisine' taxonomies to the 'post' post type
register_taxonomy_for_object_type('wprm_course', 'post');
register_taxonomy_for_object_type('wprm_cuisine', 'post');
}
add_action(‘save_post’, 'register_recipe_taxonomies_for_parent_post’);
I executed this snippet once by activating it and saving a post right after. Then I deactivated the snippet again.
Then I tried displaying these custom taxonomies using the cwicly taxonomy terms block. When I set the Source to “current” and select to include wprm_course or wprm_cuisine, the taxonomy terms block returns “Taxonomy Terms content not found”. Alternatively I tried displaying the custom taxonomy terms using the following PHP return function:
function get_post_recipe_type( $post_id ) {
// Ensure we have a valid post ID
if ( isset( $post_id ) ) {
// Specify the taxonomy you are looking for (e.g., 'course_type' or 'countries')
$taxonomy = 'wprm_course'; // Replace this with your actual taxonomy name
clean_post_cache( $post_id );
// Get the terms associated with the current post and this taxonomy
$terms = get_the_terms( $post_id, $taxonomy );
if (!empty($terms) && !is_wp_error($terms)) {
return $terms[0]->name; // Return the first term's name
} else {
return 'No terms found or error fetching terms';
}
} else {
return 'No post ID found';
}
}
add_shortcode('post_recipe_type', 'get_post_recipe_type’);
When I use this function on the post itself (e.g. site_url/recipes/banana-nicecream) I’m able to display the custom taxonomy terms for the taxonomy wprm_course. But when I use the same function inside a query block on the post archive page (e.g. site_url/recipes) it always returns the same taxonomy term – even when that recipe does not have that term.
Interestingly enough, the taxonomy terms block yields no results at all in both scenarios (i.e. on the post itself vs inside query template).
I’m launching the website next week and I’d greatly appreciate some insight as to what I might be missing. Did I regsiter the custom taxonomies in a wrong way? I don’t think so because I started setting up a filter block and I was able to correctly filter the posts by the wprm_course taxonomy – so cwicly must have succesfully registered the connection between posts and the wprm_course taxonomy.
I’m really puzzled by the fact that some cwicly blocks do seem to have access to these manually registered custom taxonomies (i.e. the filter block) and others don’t (i.e. the taxonomy terms block). Any hint you can give me would help a lot already.
Cheers and thank you for your time
Marc