Skip Navigation

[Resolved] Exclude specific posts from search on an archive page

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.

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: Asia/Karachi (GMT+05:00)

This topic contains 19 replies, has 3 voices.

Last updated by Waqar 11 months, 2 weeks ago.

Assisted by: Waqar.

Author
Posts
#2669943

The access details worked, thank you.

I've downloaded the website's clone and will be running some testing on this.

Will share the findings, as soon as this testing completes. Thank you for your patience.

#2670947

Thank you for waiting.

During troubleshooting on your website's clone, I was able to make the following custom code work, without any errors:


//eliminar equipos médicos de resultados de búsquedas en página filtros
function custom_post_type_archive_autoclaves( $query ) {
    if ( ! is_admin() && is_post_type_archive('autoclaves') ) {
        $taxquery = array(
            array(
                'taxonomy' => 'series-de-autoclaves-taxonomia',
                'field' => 'term_id',
                'terms' => array( 96 ),
                'operator'=> 'NOT IN'
            )
        );
        $query->set( 'tax_query', $taxquery );
  
    }
}
add_action( 'pre_get_posts', 'custom_post_type_archive_autoclaves' );

Note: the taxonomy slug 'series-de-autoclaves-taxonomia' is used in the code and not the slug of the target term ('autoclaves-medicas').

#2671203

Thank you Waqar.

I have added the code you have kindly provided me, but the page still doesn't work.

I f I understand correctly, in your clone works correctly, is that right?

I don't know what happened in mine, but since I have added the first version of the code, the search stopped working in general, and it still does not work even after removing the code.

Do you have any idea why this happens or how to solve it?

New threads created by Waqar and linked to this one are listed below:

https://toolset.com/forums/topic/split-archive-page-search-broken/

#2672877

Hi,
my archive page is still broken, with or without the extra code in the functions.php

Adding the code what the thing that broke the page, but I don't know why that happened or how to fix it.

Any idea on how to solve it?

Thank you in advance

#2672889

Thank you for waiting, as we had a busy forum queue over the weekend.

I've checked the archive ( hidden link ) and the custom code is working as expected to exclude the posts with the term 'Autoclaves médicas'.
( without the code there are 22 results, while with the code, there are 12 )

I've created a separate ticket for your report about the search not working and will follow up on that shortly.
( ref: https://toolset.com/forums/topic/split-archive-page-search-broken/ )

You're welcome to mark this ticket as resolved and start a new one, for each new question or concern.

#2673687

Thank you very much for your support Waqar, I am closing the ticket