Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 626 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
link to custom taxonomy by id

#1
Through a series of specific requirements, I find myself needing to link to a custom taxonomy category using its term id...

I've got this - which displays a link to all taxonomies - I wish to change it so it only displays a link to the taxonomy with the term id dynamically pulled from a custom field I'm using.

$taxonomy = 'event-categories';
$terms = get_terms($taxonomy);
if ($terms) {
foreach($terms as $term) {
echo '<li><a href="http:/mysite.com/events/categories/project-events/' . $term->slug . '">' . $term->name .'</a></li>';
}
};


essentiall I need "link_to_taxonomy_category(x)" where x = term_id

Thanks
Reply

#2
The function you are looking for is `get_term_link`. It takes either a term object, ID or slug and a taxonomy name and returns a URL to the term landing page.

As a side note hard coding the link as you have in the example above is fragile -- always keep your code as portable as possible. If the site is moved to a different domain, that link will break. WordPress has several functions that generate links dynamically based on the current installation environment. `get_term_link` is one example.

From the [Codex][1]:

$terms = get_terms('species');
echo '<ul>';
foreach ($terms as $term) {
echo '<li><a href="'.get_term_link($term->slug, 'species').'">'.$term->name.'</a></li>';
}
echo '</ul>';


[1]:

[To see links please register here]

Reply

#3
If you have single `term_id` e.g: `10`, custom taxonomy `series` then you can use the following code to get the taxonomy term link.

note : change 10 to your variable for term_id and 'series' to your taxonomy.

$term = get_term( 10, 'series' );
$term_link = get_term_link( $term );
echo '<a href="' . $term_link . '">View All</a>';
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through