WordPress.org

Ready to get started?Download WordPress

Forums

Replace a string using add_filter (2 posts)

  1. halben
    Member
    Posted 9 months ago #

    How would I change the taxonomy portfolio_category to customer_category?

    Would an add_filter & str_replace do the job?

    // Register custom post types
    add_action('init', 'pyre_init');
    function pyre_init() {
    	global $data;
    	register_post_type(
    		'avada_portfolio',
    		array(
    			'labels' => array(
    				'name' => 'Portfolio',
    				'singular_name' => 'Portfolio'
    			),
    			'public' => true,
    			'has_archive' => true,
    			'rewrite' => array('slug' => $data['portfolio_slug']),
    			'supports' => array('title', 'editor', 'thumbnail','comments'),
    			'can_export' => true,
    		)
    	);
    
    	register_taxonomy('portfolio_category', 'avada_portfolio', array('hierarchical' => true, 'label' => 'Categories', 'query_var' => true, 'rewrite' => true));
    	register_taxonomy('portfolio_skills', 'avada_portfolio', array('hierarchical' => true, 'label' => 'Skills', 'query_var' => true, 'rewrite' => true));

    Thanks,
    Hal

  2. halben
    Member
    Posted 9 months ago #

    Update:

    I did something like this, it did replace the portfolio_category to customer_category but I was not able to access the category. It keeps kicking me out because once it replaces, the portfolio category
    can not be accessible. I would probably need to mirror it, I think. If anyone have a better solution, please help.

    function custom_portfolio_to_customer_category_url($content) {
        $current_path = 'portfolio_category';
        $new_path = 'customer_category';
        $content = str_replace($current_path, $new_path, $content);
        return $content;
    }
    add_filter('term_link', 'custom_portfolio_to_customer_category_url');

Reply

You must log in to post.

About this Topic