- This topic has 5 replies, 3 voices, and was last updated 3 years, 4 months ago by
David.
-
AuthorPosts
-
December 16, 2022 at 3:46 pm #2464632
George
I have a custom taxonomy that belongs to a custom post type. I want to create a static page for a particular term. The URL is something like this:
[SITEURL]/prognosis-category/bet-of-the-day/I am using this code:
add_filter('request', function( array $query_vars ) { if ( is_admin() ) { return $query_vars; } if ( isset( $query_vars['taxonomy_name'] ) ) { $pagename = $query_vars['taxonomy_name']; if ( $pagename == 'bet-of-the-day') { $query_vars = array( 'pagename' => "$pagename" ); } } return $query_vars; } );I was wondering if this is correct as it doesn’t seem to work. I have already create a static page with the
bet-of-the-dayslug.December 16, 2022 at 5:15 pm #2464679Leo
StaffCustomer SupportHey George,
Correct me if I’m wrong here but I don’t believe this is a theme-related issue at all.
Things like the permalink structure is entirely handled by WordPress core so I’d recommend either check with their support team or post the question in a WP general forum like this:
https://wordpress.org/support/article/settings-permalinks-screen/Thanks for your understanding 🙂
December 16, 2022 at 6:27 pm #2464716George
I think it’s related, Leo. I am just trying to set a static archive page but for a custom taxonomy.
https://docs.wpshowposts.com/article/use-static-pages-as-category-archives/
https://generatepress.com/forums/topic/question-about-using-static-pages-as-category-archives/I am actually trying David’s solution here:
https://generatepress.com/forums/topic/use-static-pages-as-taxonomy-archives/December 17, 2022 at 6:34 am #2465030David
StaffCustomer Supportafter this line:
$pagename = $query_vars['taxonomy_name'];usevar_dumpto see what $pagename returnsie.
var_dump($pagename)I assume your condition here:
if ( $pagename == 'bet-of-the-day') {will return false as:
$pagename = $query_vars['taxonomy_name'];You will probably need to get the current term slug:
$current_term_slug = get_queried_object()->slug;And compare that to your page name.
eg.
add_filter('request', function( array $query_vars ) { if ( is_admin() ) { return $query_vars; } $current_term = get_queried_object()->slug; // get the term slug $match_term = 'bet-of-the-day'; if ( isset( $query_vars['taxonomy_name'] ) && $match_term == $current_term ) { $pagename = $query_vars['taxonomy_name']; $query_vars = array( 'pagename' => "$pagename" ); } return $query_vars; } );Not sure on this to be honest, never managed to get this to work for a single term before.
Alternatively, could you just build that page using a Block Element – Loop Template ?
December 21, 2022 at 9:27 am #2469674George
Hey David, I will keep the code in mind, better to go with a Loop template, I reckon.
Thanks again!
December 22, 2022 at 1:46 am #2470191David
StaffCustomer SupportSounds like a good idea 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.