Only show posts with custom field (date field) after today
-
Hi there,
wondering if it is possible to show post with custom field (date field) with date after today?
Thank you for your help!
-
Sorry for the delay response.
Yes, It is possible bur requires technical knowledge. Post Slider and Post Carousel plugin have WP Query filter which you can use and modify the query output as per your need.
For Slider query you can use the
apply_filters( 'psacp_post_slider_query_args', $args, $atts );And Carousel query you can use the
apply_filters( 'psacp_post_carousel_query_args', $args, $atts );I hope the above information will help you.
hi there,
thank you for your help, I am not very good at wordpress programming, is the code you mentioned should it be placed in the functions.php or right above the shortcode?
is it like this? (just a simple example)
$args = array(‘cat’ => 4);
apply_filters( ‘psacp_post_slider_query_args’, $args, $atts );
what should I input for the $atts?wondering if you could provide a very simple example for reference as I have browsed through https://premium.infornweb.com/post-slider-and-carousel-pro/ and cannot find the reference.
Thank you very much for your help!
Thanks for your response. No issue, I will help you with that.
Can you please tell me what exactly you want in WP Query?
I mean which type of Post you want to get. Is it specific custom field? So give me its meta key and value or is it specific category post you want to fetch?
hi there,
thank you very much for your help! I want to get posts with category id = 2 and custom field ( i believe it is called the meta field) “end_date” >= today.
Thanks alot!
Thanks for your patience. I have prepared the code but I have few queries,
First of all you have to use the shortcode with category parameter i.e.
[psac_post_slider category="4"] /* This will bring the category post. You can enter category ID or Category Slug. You can pass multiple values as a comma separated */So Post Slider and Post Carousel plugin above shortcode will do the half work. Now we want to fetch result which has custom date >= today date.
Please use this source code https://pastebin.com/raw/BJ5QXAn6 and add it to your current theme / child theme functions.php file.
This will modify the post slider output.
Now my query is,
01) Does your meta key named
end_datestores only date or it stored date and time?
02) What is the format of storage? Is it Y-m-d?Based on this a code will be modified. Right now code is written by assuming that it stored the date in Y-m-d format in database.
Hi there,
Thank you so much for your help! The time format we use is d-m-Y .
The code you provided should be place in the functions.php file? We have a few shortcode(s) of the plugin slider on the same web page with different sorting and result set, will the code affect all of them and wondering how to target only one of the sliders on the same page without affecting the others?
Thank you so much for your assistance!
For your query,
01) The code you provided should be place in the functions.php file?
Ans – Yes.02) The time format we use is d-m-Y.
Ans – OK then you need to use the same format in the given code.03) We have a few shortcode(s) of the plugin slider on the same web page with different sorting and result set, will the code affect all of them and wondering how to target only one of the sliders on the same page without affecting the others?
Ans – Actually yes it will affect all the sliders. There is no direct provision in the lite version but you can apply a little tweak.[psac_post_slider category="4" orderby="custom-date"] /* This will bring the category post. You can enter category ID or Category Slug. You can pass multiple values as a comma separated */In the above shortcode make sure you pass orderby=”custom-date” so “custom-” will be the static string and after dash (-) you should pass the original order by value. In this way it will work for that slider only which has orderby=”custom-date”.
Please try this modified code https://pastebin.com/raw/KMEmnrPS
hi there,
thank you so much for the update but I cannot get it to work, what I have here is:
[psac_post_slider design=”design-2″ show_author=”false” category=”4″ show_date=”false” show_content=”true” orderby=”custom-date” show_category=”false” dots=”false”]
and the function is :
==================================
function modify_psacp_post_slider_query_args( $args, $atts ) {
if( $atts[‘orderby’] == ‘custom-date’ ) {
$args[‘orderby’] = str_replace( ‘custom-‘, ”, $args[‘orderby’] );
// Today date
$today = date_i18n( ‘d-m-Y’, current_time(‘timestamp’) );$args[‘meta_query’] = array(
array(
‘key’ => ‘end_date’,
‘compare’ => ‘>=’,
‘value’ => $today,
‘type’ => ‘DATE’,
),
);
}return $args;
}
add_filter( ‘psacp_post_slider_query_args’, ‘modify_psacp_post_slider_query_args’, 10, 2 );=======================
what I try to use is the custom field created by ACF plugin what is “end_date” with return format as d-m-Y
Please help, thank you!!
As you are saying the ACF custom date field return value is d-m-Y.
Actually return format is different than what actually stored in the database.
Kindly check the stored value in the database. You can find it postmeta table with reference to the post id.
Please let me know what exactly it is storing in the DB.
Hi there,
thank you so much for the follow up. in ACF the field’s Display Format is F j, Y
and the Return Format is d-m-Y
please advise thank you!!
You have already provided this information previously but it is not helpful.
Kindly check the stored value in the database. You can find it postmeta table with reference to the post id.
Please let me know what exactly it is storing in the DB.
The topic ‘Only show posts with custom field (date field) after today’ is closed to new replies.