Skip Navigation

[Closed] Custom post type filters?

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 8 years, 7 months ago.

Assigned support staff: Luo Yang.

Author
Posts
#19179

Love this plugin 🙂

Ive tried many things and i cant get it perfect. Maybe someone can help me from the start?

I have a site that displays only one business or person in every city.

Custom post type: Location
Custom Taxonomy/Cat: States (usa)
Custom Post Titles: The persons business name

This is what one of my URLs would looks like: ".com/location/states/post-title"

I have a few thoughts.

1) remove "location" (custom post type slug) to get this result: ".com/states/post-title"
- Since the taxonomy in the slug doesnt link, i dont really need this in there

2) IF I cannot remove the custom post type (location) slug from the url then I would need some help making these views listed below
- ".com/location/" (simple list of all the states (taxonomies)
- ".com/location/states/" (simple filter to filter by states (taxonomy)

Im trying to make something visually fit the theme ill be using shortly. LINK: hidden link

Maybe i could use there portfolio template? It has the option on the right hand side while editing a page. This theme is responsive.

Thank you!

Chris

#19187

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Hi Chris,

I have test your codes in previous thread: https://toolset.com/forums/topic/taxonomy-shows-other-in-url/

It works for me, by modify as following:
1) change "Custom post type: Location", Use a custom URL format: %states%
2) make sure that your Custom Taxonomy/Cat: States (usa), is using slug: states,
3) modify the additional codes in your theme/functions.php as:

add_filter('post_link', 'states_permalink', 10, 3);
add_filter('post_type_link', 'states_permalink', 10, 3);

function states_permalink($permalink, $post_id, $leavename) {
if (strpos($permalink, '%states%') === FALSE) return $permalink;

// Get post
$post = get_post($post_id);
if (!$post) return $permalink;

// Get taxonomy terms
$terms = wp_get_object_terms($post->ID, 'states');
if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) $taxonomy_slug = $terms[0]->slug;
else $taxonomy_slug = 'other';

return str_replace('%states%', $taxonomy_slug, $permalink);
}

Then you will get this result: ".com/states/post-title"
To apply these change you need carefully read WordPress document:
http://codex.wordpress.org/Plugin_API/Filter_Reference
Search "post_link" and "post_type_link"

Regards
Luo

#19264

I did it but now when i view one of my custom post types, it just loops forever (doesnt work).

hidden link

#19279

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Hi Chris,

Could you build a demo site where can modify the codes, deactivate other plugin and debug codes without worry about break your live site.
Since I tested the codes in my localhost, and I guess there is some conflict in your live site.

Regards
Luo

The topic ‘[Closed] Custom post type filters?’ is closed to new replies.