WordPress.org

Ready to get started?Download WordPress

Forums

Get new variable from permalink (2 posts)

  1. Sergio De Falco
    Member
    Posted 2 years ago #

    Hi people!

    I need to get a variable appended to the permalink, that should be in a post or custom post type.

    No problem getting it when permalink are disabled, this is the code I'm using:

    function add_query_vars($public_query_vars) {
        $public_query_vars[] = 'fruits';
        return $public_query_vars;
    }

    then I get using

    get_query_var('fruits')

    The problem is with enabled permalinks.

    Using:

    add_filter('rewrite_rules_array','mycode_add_rewrite_rules');
    
    function mycode_add_rewrite_rules($rules){
    
    	add_rewrite_tag('%fruits%','([^&]+)');
    	add_rewrite_rule('^([^/]+)/([^/]+)/([^/]+)/?','index.php?pagename=$matches[2]&fruits=$matches[3]','top');
    }

    I cannot get the variable, then never occurs again 404 error when I add one or more "/" (ex. http://www.site.com/2012/06/title/first/second/third/)

    Could somebody help me resolving this?

    Thanks :)

  2. Sergio De Falco
    Member
    Posted 2 years ago #

    Everything is working now, except for the problem of the infinite / not showing 404 :\

Topic Closed

This topic has been closed to new replies.

About this Topic