Skip Navigation

[Résolu] Author fields in Posts Parametric Search

This support ticket is created Il y a 6 années et 4 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Marqué : 

This topic contains 4 réponses, has 3 voix.

Last updated by Shane Il y a 6 années et 4 mois.

Assisted by: Shane.

Auteur
Publications
#598530
AUTHOR FILTER FIELDS.png

I am refering to these threads:

https://toolset.com/forums/topic/parametric-search-by-author/
https://toolset.com/forums/topic/user-author-filter-in-a-list-view/

that make use of the author-filter in a parametric search. My question is if it could be possible to filter the posts in a parametric search by another user field except the username or the id of the author.

Thank you!

#598670

Shane
Supporter

Languages: Anglais (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ioannis,

Thank you for contacting our support forum.
Unfortunately no its not possible to pull any other information from the author because this is what wordpress provides to the posts for author information.

So you can only filter by these 2 attributes.

Thanks.
Shane

#598683

Ok, thank you Shane!

#599087

Hi Ioann,

I was talking with Shane about an issue that is related to your request and we were able to find a solution to this.

Shane will reopen this ticket again, he will ask you for more information to help him, and then offer the workaround to you ASAP.

I hope that we can offer a solution for this.

Thanks.

#599333

Shane
Supporter

Languages: Anglais (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ionnis,

I was able to think of a viable solution for this.
The solution is that you will need 2 views and a custom filter on your view.
First you will need to create a view that will list the Authors ID.
Example of the author ID view

[wpv-items-found]
    <!-- wpv-loop-start -->
        <wpv-loop>[wpv-item index=1][wpv-user field="ID"][wpv-item index=other],[wpv-user field="ID"]</wpv-loop>
    <!-- wpv-loop-end -->
    [/wpv-items-found]

On an important note that for the Author ID view you will need to use some javascript to strip the white spaces from the view. So add this to the JS section.

jQuery("#wpv_control_select_post_author > option").each(function () {
        this.value = this.value.trim();
 
    });

Then you will need the Author Meta view that lists some author meta information. In this view we are using the nickname.

[wpv-items-found]
    <!-- wpv-loop-start -->
        <wpv-loop>[wpv-item index=1][wpv-user field="nickname"][wpv-item index=other],[wpv-user field="nickname"]</wpv-loop>
    <!-- wpv-loop-end -->
    [/wpv-items-found]

Finally on our view with the parametric search view you will create a custom filter like this.

<label>[wpml-string context="wpv-views"]Post Author[/wpml-string]</label>
    [wpv-control-postmeta field="post_author" type="select" source="custom" url_param="author-filter" values="[wpv-view name='list-author-id']" display_values="[wpv-view name='list-author-name']"]

Then under the query filter you will click "Add A filter" and then add the filter for author and set it to be filtered by a URL parameter.

Also you will need to add this to your function.php file and change the ID to the id's for the 2 views that you are using.

add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 );
      
function prefix_clean_view_output( $out, $id ) {
    if ( $id == '109' || $id == '110' ) { //Please adjust to your Views ID
        $start = strpos( $out, '<!-- wpv-loop-start -->' );
        if ( 
            $start !== false
            && strrpos( $out, '<!-- wpv-loop-end -->', $start ) !== false
        ) {
            $start = $start + strlen( '<!-- wpv-loop-start -->' );
            $out = substr( $out , $start );
            $end = strrpos( $out, '<!-- wpv-loop-end -->' );
            $out = substr( $out, 0, $end );
        }
    }
    return $out;
}

Thanks,
Shane

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.