0

I created a custom page template that lists posts from a "taxonomy".

When you click on a post, I want the taxonomy and term to be passed as a parameter in the url as a query string so that i can get the taxonomy on the single post page.

Any help is appreciated.

Thanks

2

2 Answers 2

1

You can use add_query_arg, here is the example. Hope this help you

Sign up to request clarification or add additional context in comments.

1 Comment

Hi @Duc Doan, thanks for the advise. I'll look into add_query_arg example
1

I passed the value as query string to the titles within the taxonomy by using the code below:

<?php
  $theTaxonomy = get_taxonomy( get_query_var( 'taxonomy' ) ); 
  $getTaxonomy = $the_tax->labels->name;

  function to_slug($string){
      return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $string)));
  }

  $getTaxonomy;
  $getTaxonomySlug = to_slug($getTaxonomy);
  $getPermalink = esc_url(get_permalink());
  $taxonomyUrl = '?'.'type'.'='.$getTaxonomySlug;
?>

<a href="<?php echo $getPermalink.$taxonomyUrl ?>"></a>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.