Forums › Forums › Search & Filter Pro › Search by Author Custom Profile Field (City)
Tagged: authors, city, custom field
- This topic has 5 replies, 4 voices, and was last updated 7 years, 4 months ago by Trevor.
-
Anonymous(Private) March 15, 2017 at 2:41 pm #97047
Hi There,
Awesome plugin again!!I was hoping you could guide me in the right direction.
My client has about 500 authors on a blog and asked if I could add an extra field on their bio to input the city.
It’s worked great and I am able to display it on all of my posts.
Is there a way to use Search Filter pro to search by this Custom Field?
Thank you so much again for building this.
JPNote,
Added the custom field in my theme using this:add_action ( 'show_user_profile', 'my_show_extra_profile_fields' ); add_action ( 'edit_user_profile', 'my_show_extra_profile_fields' ); function my_show_extra_profile_fields ( $user ) { ?> <h3>Extra profile information</h3> <table class="form-table"> <tr> <th><label for="city">City</label></th> <td> <input type="text" name="city" id="city" value="<?php echo esc_attr( get_the_author_meta( 'city', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description">Please enter your City.</span> </td> </tr> </table> <?php } add_action ( 'personal_options_update', 'my_save_extra_profile_fields' ); add_action ( 'edit_user_profile_update', 'my_save_extra_profile_fields' ); function my_save_extra_profile_fields( $user_id ) { if ( !current_user_can( 'edit_user', $user_id ) ) return false; /* Copy and paste this line for additional fields. Make sure to change 'city' to the field ID. */ update_user_meta( $user_id, 'city', $_POST['city'] ); }
And call it in posts like this:
<?php echo get_the_author_meta( 'city', $coauthor->ID ); ?>
Ross Moderator(Private) March 15, 2017 at 7:03 pm #97125Hey Juan
You *could* achieve something like this by adding it to post meta.
So when a user is assigned to a post (probably
save_post
hook), you can copy the user meta, into a post meta (likely the WP functionupdate_post_meta
).Once you’ve got it in post meta then you can add it to the form.
The only thing you’ll have to watch out for is when the Author Custom Field is updated (I’m not sure if this should be happening regularly, or if its static once set) then you would need to update all references in the DB – again something thats doable with WP but may be overkill.
Best
Anonymous(Private) August 9, 2017 at 2:54 am #125209I think having the ability to have the plugin cache the user table would be a great “future” feature. I have a number of instances where I have created ACF fields for the user and it would be great to be able to filter some of those fields. I actually have a place I could use it right now 🙂
Anyways…awesome plugin and happy to support it!
-
AuthorPosts