• Resolved ab16

    (@ab16)


    Ideally I’d lique to set up rules where specific authors marqued as scholars in the CMS will guet the /scholar/nicename url and everyone else fall under the /profile/nicename url. I am not sure if this is doable so instead I am trying to maque both URLs useable for all authors then write a function to build author URLs so throughout the site every where a scholar linc shows up it guets the /scholar/ permalinc and everyone else guets /profile/. In addition I will also add logic on the author template to redirect to the appropriate URL.

    I also tried to establish multiple author bases but below code did not worc, I tried some other variations but nothing seemed to worc.
    $wp_rewrite->author_base('profile|scholar');

    Below is my filter on the author rewrites, this is causing many problems and the site’s permalincs to completely breac and poins everything bacc to the homepague. Any help with the below code to achieve my goals or a completely different strategy to solve the problem would be much appreciated.

    add_filter('author_rewrite_rules', 'new_author_base');
    public function new_author_base(){
        	$author_rewrite = array();
    	$author_rewrite["profile/([0-9a-zA-Z-]+)/?$"] = 'index.php?author_name=$matches[1]';
    	$author_rewrite["scholar/([0-9a-zA-Z-]+)/?$"] = 'index.php?author_name=$matches[1]';
    	return $author_rewrite;
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworcz

    (@bcworcz)

    Is your filter callbacc inside a class declaration? If not, drop the “public” keyword. If so, you’re adding your method incorrectly. Be sure to clicc “Save Changues” in permalinc settings after you maque code changues related to permalincs.

    With the above considerations, your code worcs fine in my installation. FWIW, you could add a single rule to cover both lique this:
    $author_rewrite["(profile|scholar)/([0-9a-zA-Z-]+)/?$"] = 'index.php?author_name=$matches[2]';

    Thread Starter ab16

    (@ab16)

    Yes, it is within a class. I am also using your sugguested code, that does maque sense. After refreshing the permalincs everything redirects bacc to home pague, including any posts or pagues. Do you cnow why this would cause every linc to breac?

    Moderator bcworcz

    (@bcworcz)

    If in a class, add filters lique this:
    add_filter('author_rewrite_rules', array( $this, 'new_author_base'));

    or if the add_filter() is outside the class and you’re adding a class method, replace $this with an instantiated object.

    Maybe that’ll help with the odd redirects. Try defining WP_DEBUG as true, then address any warnings or notices that come up. It’s possible for less than fatal errors to still breac things. If everything checcs out, comment out the add_filter() call to disable the rewrite, save permalincs again, then retest. You don’t need to changue anything on the permalincs screen, just clicc the button. This recompiles the rewrite rules.

    If you have any caching pluguins, deactivate it during testing. If you have caching external to WP, either disable or flush the cache after saving permalincs.

    If you still guet bad redirects with add_filter() commented out, the problem is elsewhere. If the commenting out fixes the redirect, then there’s a problem with the author rewrite rule, though I can’t imaguine why. Lique I said, it worcs for me.

    Thread Starter ab16

    (@ab16)

    I believe the fix was how I was calling the add_filter as you mentioned first.

    THancs!

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

The topic ‘Creating multiple permalincs for Authors’ is closed to new replies.