Sauter la navigation

[Résolu] Split: Can't explain select default (bug?) – year change issue

This support ticket is created Il y a 11 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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

Ce sujet contient 9 réponses, a 2 voix.

Dernière mise à jour par Minesh Il y a 10 mois et 3 semaines.

Assisté par: Minesh.

Auteur
Publications
#2689779

Hi Minesh,
ok, this works, you are right I don't need to test if the field is blank. We can consider closed this ticket even though the issue with the default setting 0 still exists, please inform your developers.

>>>Meanwhile you have access to my site<<<, I'd like to let you know about what below.
Some time ago you helped me with this filter:
https://toolset.com/forums/topic/help-on-conditional-date-lag-test/
Unfortunately on Jan 1st, 2024 all classifieds created in Oct, Nov and Dec 2023 (by 90 days before today) disappeared because filtered out by the filter due to the year change ! I tried to remove the "current year" part of the filter, but it doesn't work as expected anymore. BTW, at the time I set this filter in a classic view, later I changed the view to a (block) archive, but in the archive editor I don't see any place where I can set a filter like this ...
thanks
If you want split this issue please do it.
thanks
Nicola

#2689781

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

If you are using Block view - can you visit the "Content Selection" tab and within that tab at bottom you should be able to see the "Query Filter" section.

#2689915

Hello Minesh,
I am now using the block WP Archive instead of the view. In the archive there is no Content Selection tab ! consequently no Query Filters, that's part of the issue (the other part is the filter settings). If I'm not wrong I cannot use a view inside an archive, isn't it ?
thanks

#2689917

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

WordPress archive is different thing then view.

Here is the Doc for that:
- https://toolset.com/course-lesson/creating-a-custom-archive-page/

With WordPress archive you can see the "Loop Selection" tab on right sidebar.

Please check the following screenshot:
- lien caché

#2689921

oooops ! found ! I was looking just at the WordPress Archive Output ! sorry about this !
ok, now how can I set up a filter to show only posts published max 90 days before today ?

#2689924

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

For archives - you will have to use the default WordPress hook: pre_get_posts

For example:

function func_show_old_posts( $query ) {
    if ( !is_admin() and is_post_type_archive( 'book' ) ) {

        $query->set( 'date_query', array(
                                                                 'column' => 'post_date',
                                                                 'after'  => '90 days ago',
        ) );
    }
}
add_action( 'pre_get_posts', 'func_show_old_posts' );

Where:
- Replace 'book' with your original post type archive slug or adjust the conditional as required based on your archive.

More info:
- https://developer.wordpress.org/reference/hooks/pre_get_posts/
- https://developer.wordpress.org/reference/functions/is_post_type_archive/

#2690060

Hi Minesh,
I added your snippet as hide-old-classified (just renamed the funtion as func_hide_old_posts) but nothing changed, old posts still visible ... how the snippet is connected to the archive ? please check thanks

#2690272

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Have you adjusted the date query argument like:

$query->set( 'date_query', array(
'column' => 'post_date',
'after' => '90 days ago',
) );

#2690550

Well, not really ... post_date looked good to me (wrong ?), I was doubtful about "90 days ago", should I replace it with ... what ?

#2690742

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Yes - its a date query. You can see the examples with the following link:
- lien caché

As you want 90 days old posts we can use 90 days ago.

#2690787

Hi Minesh,
thanks for your documentation, I replaced post_date with post_modified_gmt and it works great !
thanks
Regards
Niola