I don’t know the context, but i got your use case working like this:
Add new permastruct and make sure to regenerate permalinks (Settings > Permalinks > Save)
/**
* Add additional permalink
*
* @uses https://codex.wordpress.org/Plugin_API/Action_Reference/init
*/
function wpte_add_permastruct(){
add_permastruct( '%author_trip_vendor%', 'operator/%author%', [
'ep_mask' => EP_AUTHORS,
]);
}
add_action( 'init', 'wpte_add_permastruct' );
Added this to init action.
Next alter the WP Query on author query (is_author() === true condition)
/**
* Change query when is_author() is true
*
* @uses https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
*/
function wpse33150_alter_query($query) {
// Do not apply if not $querying "author"
if ( ! is_author() )
return;
// Set query for author meta
$query->set( '_private_author_query', [
[
'key' => 'company_name',
'value' => get_query_var('author_name'),
'compare' => '=',
]
]);
return $query;
}
add_action( 'pre_get_posts', 'wpse33150_alter_query' );
This is added to pre_gest_posts action
Now when you enter endpoint /operator/company-name the query will be altered to query by “company-name”.
Just for reference i’m also adding implementation of the author meta field.
/**
* Add meta field company_name to user
*/
function wpse33150_user_profile_fields( $user ) { ?>
<table class="form-table">
<tr>
<th>
<label for="company_name"><?php _e('Company name'); ?></label>
</th>
<td>
<input type="text" name="company_name" id="company_name" value="<?php echo esc_attr( get_the_author_meta( 'company_name', $user->ID ) ); ?>" class="regular-text" />
</td>
</tr>
</table>
<?php }
add_action( 'show_user_profile', 'wpse33150_user_profile_fields' );
add_action( 'edit_user_profile', 'wpse33150_user_profile_fields' );
/**
* Update meta field company_name to user on update
*/
function save_wpse33150_user_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) ) {
return false;
}
update_user_meta( $user_id, 'company_name', $_POST['company_name'] );
}
add_action( 'personal_options_update', 'save_wpse33150_user_profile_fields' );
add_action( 'edit_user_profile_update', 'save_wpse33150_user_profile_fields' );