Skip Navigation

[Resuelto] How to remove posts displayed using post id filter

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

Problem: I have a View that uses a post ID filter based on a URL parameter. I am able to use the URL parameter array to show multiple posts in the View results. I would like to be able to allow my Users to click a button next to any result to remove that result from the list, and show an updated list of results. For example, here is the URL format for the View:
@http://mysite.com/?post_ids%5B%5D=24&post_ids%5B%5D=23&post_ids%5B%5D=22&post_ids%5B%5D=21&s=

I would like to be able to click a button next to post ID 23 and end up at a URL like this:
@http://mysite.com/?post_ids%5B%5D=24&post_ids%5B%5D=22&post_ids%5B%5D=21&s=

Solution: I can't think of any easy way to do this without some JavaScript URL manipulation. Something like this:

jQuery('#wpv-supplier-comparison :submit').click(function(e){
  e.preventDefault();
  var url = window.location.href,
    val = jQuery(e.target).val(),
    firstVarString = '?post_ids%5B%5D=' + val,
    notFirstVarString = '&post_ids%5B%5D=' + val,
    firstVarPos = url.indexOf(firstVarString),
    notFirstVarPos = url.indexOf(notFirstVarString),
    pos = firstVarPos > -1 ? firstVarPos : notFirstVarPos,
    varString = firstVarPos > -1 ? firstVarString : notFirstVarString,
    urlArray = url.split(varString, 2),
    newUrl = urlArray[0] + urlArray[1];
 
  if(newUrl.indexOf('?') < 0) {
    newUrl = newUrl.substr(0,newUrl.indexOf('&')) + '?' + newUrl.substr(newUrl.indexOf('&')+1);
  }
  window.location.href = newUrl; 
});
This support ticket is created hace 6 años, 6 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Etiquetado: ,

Este tema contiene 2 respuestas, tiene 2 mensajes.

Última actualización por davidR-12 hace 6 años, 6 meses.

Asistido por: Christian Cox.

Autor
Mensajes
#902159
FireShot Capture 004 - Edit View ‹ 3D Net — Word_ - https___3dnet.foxrobinson.com_wp-admin_admin.php.jpg

I have a page here:

enlace oculto

The page is set to display posts using the post id filter (Image attached)

I have then set them to display with a button with a value of their post id:

<form id="wpv-supplier-comparison" action="[wpv-bloginfo show='url']/marketplace-enquiry-from-page/">
<input type="submit" name="post_ids[]" value="[wpv-post-id]">
</form>

clicking on this refreshes the page and removes all other posts.

What i want it to do is to refresh the page and remove the post that is clicked on rather than removing all other ones. How can I do this?

Regards,

David

#902213

Hi, I don't know of an easy way to do this without some JavaScript URL string manipulation. Something like this might be useful:

jQuery('#wpv-supplier-comparison :submit').click(function(e){
  e.preventDefault();
  var url = window.location.href,
    val = jQuery(e.target).val(),
    firstVarString = '?post_ids%5B%5D=' + val,
    notFirstVarString = '&post_ids%5B%5D=' + val,
    firstVarPos = url.indexOf(firstVarString),
    notFirstVarPos = url.indexOf(notFirstVarString),
    pos = firstVarPos > -1 ? firstVarPos : notFirstVarPos,
    varString = firstVarPos > -1 ? firstVarString : notFirstVarString,
    urlArray = url.split(varString, 2),
    newUrl = urlArray[0] + urlArray[1];

  if(newUrl.indexOf('?') < 0) {
    newUrl = newUrl.substr(0,newUrl.indexOf('&')) + '?' + newUrl.substr(newUrl.indexOf('&')+1);
  }
  window.location.href = newUrl; 
});
#902217

Hi Christian,

Thank you for that code which works perfectly! Thank you very much!

Cheers,

David