Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #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.
    #1378210

    Hey 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,
    Ismael

    #1378211

    Hello 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 achieve

    #1378215

    Hi!

    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,
    Ismael

    #1378222

    In 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

    #1378328

    Hello Ismael,

    Please, confirm that we are on the same page
    Will I be able to write %category% in the portfolio item base field?

    #1378354

    I 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 you

    #1378358

    Hi,

    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,
    Ismael

    #1378359

    Hi,

    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,
    Ismael

    #1378362

    Hi 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?

    #1378530

    Hi,

    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,
    Ismael

    #1378555

    Thanks 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 future

    #1378841

    Hi,

    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,
    Yigit

    #1378842

    Thanks 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

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.