Skip Navigation

[Resuelto] View: custom field filter doesn’t keep post relationship filter when filtering

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:
The user is filtering a view using a relationship field and a URL param. After filtering using AJAX, the view loses the filter because the URL parameter is not preserved.

Solution:
To fix this, we need to add a hidden field that will keep the value of the URL param. This needs custom code such as:

add_filter( 'wpv_filter_end_filter_form', 'prefix_add_hidden_field_edition_id', 99, 3 );
function prefix_add_hidden_field_edition_id( $out, $view_settings, $view_id ) {
    $views = array( 9286 );
    if ( in_array( $view_id, $views) ) {
      $edition_id = isset($_GET['edition_id']) ? $_GET['edition_id'] : '';
      $out = '<input type="hidden" id="edition_id" name="edition_id" value="' . $edition_id . '" class="js-wpv-filter-trigger form-control" />' . $out;
    }
    return $out;
}

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_end_filter_form

This support ticket is created hace 3 años, 10 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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

Supporter timezone: Africa/Casablanca (GMT+01:00)

Este tema contiene 7 respuestas, tiene 3 mensajes.

Última actualización por Zayne hace 3 años, 10 meses.

Asistido por: Jamal.

Autor
Mensajes
#1897519
Screenshot 2021-01-07 at 17.23.12.png
Screenshot 2021-01-07 at 17.20.03.jpg
Screenshot 2021-01-07 at 17.17.16.png

I have a post relationship filter that gets all the Works in an Edition:

Select posts in a Editions Works relationship that are related to the Post with ID set by the URL parameter edition_id.

When these results are shown, I have a custom field filter that can then further filter these results based on the field called Medium:

Select items with field:
Medium is a string equal to URL_PARAM(wpv-wpcf-medium)

This allows me to see all of that editions works that are SATB, SAATB, orchestra, etc. At this point the dropdown correctly shows me ONLY those mediums that exist for the specific edition I'm in.

However, as soon as a choose a medium, the original post relationship is lost and I can suddenly see ALL the mediums for ALL editions on the site.

Have a look at the screenshots attached.

So my question is: how do I keep the original post relationship filter in place when using the custom field filter?

#1898207

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please share problem URL from where I can select the Editor and share access details so I can review your current setup.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1898377

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Thank you for sharing access details but when I try to access your site - I see blank page with the following error:

This site can't be reach.
edafrican-composers-edition.co.za took too long to respond.

Is there any country wise restriction or blocking? if so, can you please remove those for now so that I can access your site.

#1898419

It looks like you’re using the incorrect url. It’s

enlace oculto

#1898491

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

I'm using the same site URL but somehow its not accessible at this end so I'm passing this ticket to Jamal who is having access to it.

#1898533

Thanks Minesh. I'm not sure why you can't get to the URL. I'll check the logs and see.

#1898683

Hello,

I logged into your website and checked this issue. When the AJAX search is performed and results are pulled the URL loses the edition_id. We can work around it by adding a hidden field to the view's search form that will hold the edition_id. This way, when AJAX calls have performed the view will get the edition_id from the hidden field and use it for filtering.

I added a snippet to Toolset->Settings->Custom Code that adds the hidden field:

add_filter( 'wpv_filter_end_filter_form', 'prefix_add_hidden_field_edition_id', 99, 3 );
function prefix_add_hidden_field_edition_id( $out, $view_settings, $view_id ) {
    $views = array( 9286 );
    if ( in_array( $view_id, $views) ) {
      $edition_id = isset($_GET['edition_id']) ? $_GET['edition_id'] : '';
      $out = '<input type="hidden" id="edition_id" name="edition_id" value="' . $edition_id . '" class="js-wpv-filter-trigger form-control" />' . $out;
    }
    return $out;
}

Please note, that the hidden field needs to have the class "js-wpv-filter-trigger" on it to work as expected.

Can you check now if this solves the issue or if I missed something else?

#1900747

Thanks! This works now. Much appreciated.