Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • Forum: Plugins
    In reply to: conditional rewrite rules
    Thread Starter vsandvold

    (@vsandvold)

    Any help is appreciated, guys.

    Forum: Plugins
    In reply to: conditional rewrite rules
    Thread Starter vsandvold

    (@vsandvold)

    What I get is this:
    * concerts/ and venues/ don’t work
    * concerts/year/month/day/postname shows all concerts, what I would like concerts/ to do
    * Same for venues/

    Forum: Plugins
    In reply to: conditional rewrite rules
    Thread Starter vsandvold

    (@vsandvold)

    So far I tried the following, without getting what I want:

    add_filter('rewrite_rules_array', 'my_rewrite');
    function my_rewrite($rewrite) {
    	global $wp_rewrite;
    
       	$category_rules = array(
            	'concerts/' => 'category/concerts/',
            	'venues/' => 'category/venues/'
        	);
    
    	$concert_post_structure = $wp_rewrite->root . "concerts/%year%/%monthnum%/%day%/%postname%/";
    	$venue_post_structure   = $wp_rewrite->root . "venues/%postname%/";
    
    	return ( $rewrite
    		+ $category_rules
    		+ $wp_rewrite->generate_rewrite_rules($concert_post_structure)
    		+ $wp_rewrite->generate_rewrite_rules($venue_post_structure)
    	);
    }

    Thread Starter vsandvold

    (@vsandvold)

    Thank you, Otto42!

    Thread Starter vsandvold

    (@vsandvold)

    Thanks for the thorough explanation, Otto42!

    So if I understand this right, add_action will hook a function to an action every time a page is loaded. The hooks then disappear when the page is done loading, because they aren’t persistent, and must be re-created for the next page load.

    Seems to me this may add some runtime overhead for page requests, especially if my plugin grows and the site gets a lot of traffic. If I want to optimize my plugin, should I try to detect the context (view vs. admin), in order to execute only the code that is required? Or is WP already so optimized that this will have little effect?

    Thanks again for spelling it out ??

    BTW, what do you call the part of PHP script not contained within a function, class or a conditional block?

Viewing 5 replies - 1 through 5 (of 5 total)