Forums Forums Search & Filter Pro Search by Author Custom Profile Field (City)

Viewing 6 posts - 1 through 6 (of 6 total)
  • Anonymous
    #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.
    JP

    Note,
    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 ); ?>

    Trevor
    #97065

    Sadly not. We do not cache the user table, where that data would/might be stored. We only index the author ID’s found in the posts table. It is possible such functionality may come in future versions, but not soon.

    Ross Moderator
    #97125

    Hey 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 function update_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
    #97815

    Got it,
    Thank you so much for the quick follow up! @trevor. Keep up the great work!

    Thanks for this @Ross! Giving it a try.
    JP

    Anonymous
    #125209

    I 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!

    Trevor
    #125263

    It is on our to do list.

Viewing 6 posts - 1 through 6 (of 6 total)