Thanks, i got it now; indeed with meta_query.
function my_recent_posts_shortcode( $atts ) {
global $post;
$currenttime = current_time("mysql");
$args = array(
'post_type' => 'post',
'meta_query' => array(
array(
'key' => 'newsbox-date',
'value' => $currenttime,
'compare' => '>'
)
)
);
$newsbox = new WP_Query( $args );
if ( $newsbox->have_posts() ) :
$list="<div class="newsbox-posts">";
while ( $newsbox->have_posts() ) : $newsbox->the_post();
$list .= '<h4>' . get_the_title() . '</h4>' . get_the_content() . '';
endwhile;
$list .= '</div>';
endif;
wp_reset_query();
return $list;
}
add_shortcode( 'recent-posts', 'my_recent_posts_shortcode' );
Related Posts:
- WP_Query orderby date not working
- How to paginate wordpress [gallery] shortcode?
- Get Recent Posts by Date in Multisite
- What kind of object type is WP_Query?
- WordPress Custom Query to show posts from last x years
- Last post ordered by publish date using WP_Query on front page
- Shortcode returns escaped HTML tags
- WP_Query in a shortcode
- How can I hide posts that are over 2 years old
- Date query not inclusive despite parameter being true
- ‘&’ causes an error in my shortcode when I list the content of the page
- Use meta_query to display events by date in custom field
- Can certain (site-crashing) limitations on WP_Query in shortcode be overcome?
- Ordering by meta_value AND date NOT WORKING with wp_query
- How to show recent and upcoming birthdays using meta_query
- How to retrieve current page WP_Query arguments?
- Meta Query for specific months
- WP_Query meta_query >= date
- wp_query add arguments using array_push if variable met
- Category attribute not working in custom shortcode
- Complex date range with WP_Query and BETWEEN
- Comparing dates in custom field
- How to display upcoming events by dat with Modern Events Calendar Lite
- How to get all child pages in their parent page?
- Orderby ASC changes to DESC in WP_Query
- Database Queries Optimization with new WP_Query
- Complex WP_Query order request: DESC by day, but then ASC by time
- Orderby is working with one query but not with other
- WP_Query: Group events by year, sorted DESC; then by date for each year group, sorted ASC
- Taxonomy and Date in same query?
- date_query seems to be ignored by wp_query
- Gallery shortcode numerical sorting
- WP Group posts by year(desc) > month(desc) > date(asc)
- How to filter a query by date in a shortcode?
- How should I approach changing the template & $query as part of a shortcode’s execution?
- Display Current Post’s Position in Custom Taxonomy
- WordPress Custom Search Form Displaying Unexpected Results
- Shortcode Not Working in Slider When Added To Post Title
- Shortcode for custom query not returning results when attributes are added
- How to Display Shortcode in the correct location, currently displaying before content after Page Title?
- Filtering posts by archive showing all years
- WP_query only displays one of my custom post type entries
- Assign a minimum result count for WooCommerce query shortcodes?
- Using a Shortcode to List Posts from Multiple Categories
- embedding shortcodes in php template
- Ordering posts by custom field and grouped by month
- Limit loop to future events
- How to show list of posts with custom field value (a date) that are coming soon
- Show single posts date, in a page of posts
- How to get specific string in explode array?
- Added Date Filter To Popular Posts Query
- Trouble passing attribute into shortcode function
- Woocommerce Shortcode which displays a table with product data
- WP Query by 4 different taxonomies
- create custom shortcode wp and put php code in
- Comparing Meta Field date in WPQuery using Meta_Query?
- How to get only present and past posts with post_date
- WP Query for all events prior to current date
- How to display a post(by id) along with css in a page?
- Problem with my loops
- Shortcode attributes causes 500 error after updating the page
- Sort posts on custom field AND after that sort on date?
- pages shortcode filtering by category
- WP_Query & shortcode : Return 3 articles from a category WordPress
- Get posts by birthday
- Query by Category and Custom Field – Shortcode
- How to take parameters from a function and make them editable as attributes in a shortcode
- How to modify WP Query to target the first most recent post to adjust content
- Object of class WP_Query could not be converted to int inside shortcode
- How can I create another instance of my custom shortcode
- Get Current CPT taxonomy category in shortcode
- Custom shortcode not displaying categories and correct date
- return wp query results in a shortcode
- More efficient query to display posts in same sub-category?
- Having Trouble Running Query From Shortcode Using Tribe’s Events Plugin
- Year based WP Query
- Get post closest to today
- Query custom post type by date field only working when two posts match the query
- Get posts from similar time as current post
- Divide WP_Query posts by date & post type
- Query Posts by date range with fixed beginning and end
- Issue with sorting by post date and custom post type
- shortcode using multiple WP_Query’s with multiple category names not fully functional
- Shortcode does not display pagination [duplicate]
- How to write a query-function as a query-shortcode?
- shortcode with $atts with strange results
- Get posts that were most recently tagged
- WP_Query sort by ACF date field (newest first) with blank dates first
- WP_query shortcode inside acf Repeater breaks the repeater loop
- How to prevent WP query searching in executed shortcodes
- Is there a way to extend WP_query so Custom Post Types can have properties?
- Pagination doesn’t work in custom page template [duplicate]
- wp_query a single custom post type?
- get data match with extra field value using wp_query for custom post
- Append URL query to next post link in custom query
- What does $temp do?
- Is instantiating WP_Query not possible within an admin Ajax call?
- Using the same WP_Query for shop and widgets in WooCommerce shop
- Order posts by more than one variable (meta_key and publish date AND time)
- How can I get all the posts that are related with a specific taxonomy term?