[Plugin: self build] Select posts with a set date
-
Hello,
I’ve just built my own plugin which basically displays posts on the frontpage which have a custom field called “featureddate” set to a date which is in the past. If the date is either a date in the future, or no featureddate is set at all, it should not display the post.
The code I have is as follows:
<? function only_featured( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set('meta_key', 'featureddate'); $query->set('meta_compare', '<='); $query->set('meta_value', date('Ymd')); } } add_action( 'pre_get_posts', 'only_featured' ); ?>The problem I have now, is that it indeed only selects posts which have the featureddate in the past. But when I don’t set a date at all, it displays the post anyway.
Does anybody know how I can solve this so that when the featureddate is not set a at it doesn’t display the post on the front page? All tips are welcome!
The topic ‘[Plugin: self build] Select posts with a set date’ is closed to new replies.