WordPress.org

Support

Support » Plugins and Hacks » Clever URL's

Clever URL's

  • sdls
    Member

    @simon_said

    hey there Scribu!

    Hoping you can help… I’m wondering if you’ve exlored custom URL sequence for related posts… for example.

    Post Type 1 – Fruit
    – Gala Apples
    – Oranges
    – Bananas

    Post Type 2 – Farmers Markets
    – Lower fairview
    – Waterfront
    – ect…

    Desire url sequence: /<market-name>/<fruit-name>

    So for “gala apples” associated with “lower fairview” url for the gala apples single page would look like “lower-fairview/gala-apples/”

    Any thoughts would be greatly appreciated.

    http://wordpress.org/extend/plugins/posts-to-posts/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author scribu
    Member

    @scribu

    sdls
    Member

    @simon_said

    thanks for the ultra quick response Scribu! Can’t seem to find the answer on the page you’ve suggested

    Are you suggesting I look at this tutorial?
    http://matty.co.za/2009/11/custom-url-rewrites-in-wordpress/

    Doesn’t seem to be the same requirements as what Rayken is looking for. I’m a bit of a newb to this topic, so please excuse my slowness in understanding

    Any insight would be greatly appreciated.

    sdls
    Member

    @simon_said

    Rayken’s example is the closest I can find to a plug and play code. The key difference is in his example the first url chunk is fixed. i.e. ‘spare-parts/’ whereas I’m hoping to make this flexible.

    // the rules
    function custom_p2p_rewrites() {
        global $wp_rewrite;
    
        // Define custom rewrite tokens
        $rewrite_tag = '%productName%';
    
        // Add the rewrite tokens
        $wp_rewrite->add_rewrite_tag( $rewrite_tag, '(.+?)', 'products=' );
    
        // Define the custom permalink structure
        $rewrite_keywords_structure = $wp_rewrite->root . "/spare-parts/$rewrite_tag/";
    
        // Generate the rewrite rules
        $new_rule = $wp_rewrite->generate_rewrite_rules( $rewrite_keywords_structure );
    
        // Add the new rewrite rule into the global rules array
        $wp_rewrite->rules = $new_rule + $wp_rewrite->rules;
    
        return $wp_rewrite->rules;
    }
    
    // add to query vars
    function add_custom_p2p_rewrites( $public_query_vars ) {
        $public_query_vars[] = 'products';
        return $public_query_vars;
    }
    
    // flush
    function flush_custom_rules() {
        global $wp_rewrite;
        $wp_rewrite->flush_rules();
    }
    
    add_action( 'init', 'flush_custom_rules' );
    add_action( 'generate_rewrite_rules', 'custom_p2p_rewrites' );
    add_filter( 'query_vars', 'add_custom_p2p_rewrites' );

    Thanks thanks thanks for your help

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Clever URL's’ is closed to new replies.