$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>plugin development - Author Meta in Author URL Link|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

plugin development - Author Meta in Author URL Link

matteradmin10PV0评论

I am trying to modify the default author link url structure. In the URL, I would also like to change the string author to operator add some author meta along with the username.

So far, I have successfully changed the string author to operator but I would also like to add the country (author meta) he/she belongs in the url. So the modified url should be like this: example/country-name/operator/newuser

Can someone help me on this?

I am trying to modify the default author link url structure. In the URL, I would also like to change the string author to operator add some author meta along with the username.

So far, I have successfully changed the string author to operator but I would also like to add the country (author meta) he/she belongs in the url. So the modified url should be like this: example/country-name/operator/newuser

Can someone help me on this?

Share Improve this question edited Feb 14, 2019 at 5:47 saurav.rox asked Feb 14, 2019 at 4:54 saurav.roxsaurav.rox 2051 silver badge13 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

This is just an example / idea and I haven't tested if this really works. But I think it could be something along these lines.

function custom_author_base() {
    global $wp_rewrite;
    global $wp_query;
    // On author pages you get current author for example with $wp_query
    $curauth = $wp_query->get_queried_object();
    // Get the required data
    $country = get_user_meta($curauth->ID, 'country_meta_key', true);
    // Turn the country into url friendly format and prepend it to operator
    $author_slug = sanitize_title($country) . '/operator';
    // Set the custom string as author base
    $wp_rewrite->author_base = $author_slug;
}
add_action('init', 'custom_author_base');

This example will propably need some tweaking. You might also need extra functions to handle other cases than the auhtor page where the author page url is shown. E.g. get_author_posts_url might need some tweaking I guess.

I hope this helps you achieve the result you're looking for. Or perhaps others can build on this and help you find a more complete solution.

Post a comment

comment list (0)

  1. No comments so far