-
AuthorPosts
-
January 11, 2023 at 2:27 am #1378195
Hello guys,
my website URL: geoevent.net
What I am trying to achieve is to use a category variable (so that it dynamically gets the right category for the product) for the portfolio item base, but it does not support special characters
Please, let me know how to remove “portfolio item” from URL and use the correspondent category instead (e.g. sound rental, backline rental, etc.)
Thank you
- This topic was modified 1 year, 10 months ago by manchust.
January 11, 2023 at 7:53 am #1378210Hey manchust,
Thank you for the inquiry.
This is possible but you can only append the first category after the base URL. Please create a site backup or restore point (this is important), then add the following code in the functions.php file. Afterwards, go to the Settings > Permalinks panel and resave the settings to flush the permalinks.
add_filter('avf_portfolio_cpt_args', 'avf_portfolio_cpt_args_mod', 10); function avf_portfolio_cpt_args_mod($args) { $args['rewrite']['slug'] = '%portfolio_entries%'; $args['rewrite']['with_front'] = false; return $args; } add_filter( 'post_type_link', 'ava_remove_custom_slug', 9999, 3 ); function ava_remove_custom_slug( $post_link, $post, $leavename ) { if ( 'portfolio' != $post->post_type || 'publish' != $post->post_status ) { return $post_link; } $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link ); return $post_link; } add_filter('post_link', 'portfolio_permalink', 1, 5); add_filter('post_type_link', 'portfolio_permalink', 1, 5); function portfolio_permalink($permalink, $post_id, $leavename) { if (strpos($permalink, '%portfolio_entries%') === FALSE) return $permalink; $post = get_post($post_id); if (!$post) return $permalink; $terms = wp_get_object_terms($post->ID, 'portfolio_entries'); if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) $taxonomy_slug = $terms[0]->slug; else $taxonomy_slug = 'no-portfolio'; return str_replace('%portfolio_entries%', $taxonomy_slug, $permalink); }
Best regards,
IsmaelJanuary 11, 2023 at 7:58 am #1378211Hello Ismael,
Thank you for your reply
What do you mean by “first category”?
I need to be sure that you understand what I want to achieveJanuary 11, 2023 at 8:08 am #1378215Hi!
By “first category”, we meant the very first category where a specific portfolio item belonged. If the portfolio item belongs to multiple categories, the modification above will select the very first category and append it to the base URL.
Best regards,
IsmaelJanuary 11, 2023 at 9:51 am #1378222In other words, url will look like domain/category/product?
Please note, category should be different for the products, but one product has only one parent category
Let me know if you need more clarification
Manu
January 11, 2023 at 11:45 pm #1378328Hello Ismael,
Please, confirm that we are on the same page
Will I be able to write %category% in the portfolio item base field?January 12, 2023 at 9:02 am #1378354I tried the code you sent but it does not work as it should
It is destroying the main page layout and for some reason, it converted the page to a portfolio category
On the other hand, it works for portfolio item pages and URLs show a right pattern
please let me know how to use your code and keep the main page layouts
Thank youJanuary 12, 2023 at 10:02 am #1378358Hi,
Did you set the Permalink structure to Postname (/%postname%/)? The Portfolio Items Base and the Portfolio Categories Base should be set to default, portfolio-item and portfolio_entries respectively. Please go to the Settings > Permalinks panel, check the settings and resave.
Best regards,
IsmaelJanuary 12, 2023 at 10:03 am #1378359Hi,
UPDATE: Looks like the filter causes errors for pages. Please remove the filter for now. Have you tried this plugin instead?
// https://ga.wordpress.org/plugins/custom-post-type-permalinks/
Please make sure to create a backup or a restore point before using the plugin.
Best regards,
IsmaelJanuary 12, 2023 at 10:07 am #1378362Hi Ismael,
To be honest I don’t want to install new plugin for such a simple functionality
Portfolio category and entires are set to default
Any workarounds?
January 13, 2023 at 8:19 am #1378530Hi,
As you have noticed, the solution that we recommended above works correctly for the portfolio items but it breaks the default post types such as pages and posts. Unfortunately, we are not yet sure why this is happening. Using the plugin might solve the issue.
Best regards,
IsmaelJanuary 13, 2023 at 10:51 am #1378555Thanks Ismael
Guys, it’s your theme and the functionality should be very easy to incorporate but for some reason, it is not, it’s reasonable to see category names instead of static “portfolio item” that does not really make any sense to be honest (in most cases at least)
Hope you will fix this in the nearest futureJanuary 16, 2023 at 12:31 pm #1378841Hi,
We have forwarded your request to our devs and shared this thread as reference. We will post the updates regarding your request here :)
Best regards,
YigitJanuary 16, 2023 at 12:37 pm #1378842Thanks a lot Yigit,
Since this is a premium theme it has to have that option so that guys who buy it can personalize and tailor to their needs.
Looking forward to updates soon
-
AuthorPosts
- You must be logged in to reply to this topic.