How to display custom post type ordered by a custom field date

The correct array key to use is meta_key, not key. You can only use key as part of a meta_query subarray, where the ‘meta’ part is implied. This is all described in the codex. Try <?php $activities = new WP_Query( array( ‘post_type’ => ‘timeline’, ‘posts_per_page’ => -1, ‘meta_key’ => ‘activity-date’, ‘orderby’ => ‘meta_value_num’, ‘order’ => … Read more

Organize content by month? SQL statement?

Just guessing, but try this: $args = array( ‘post_type’ => ‘my_content’, ‘orderby’ => ‘meta_value’, ‘meta_key’ => ‘start_month’, ‘meta_query’ => array( array( ‘key’ => ‘start_month’, ), ), ); $thisQuery = new WP_Query( $args );

Thirtieth century date for a post

Why not changing the loop? Inside the loop, just check to see if the custom-field or post-meta which you provided for the custom date is filled or not and show the post date or custom date according to the conditions. You can also have a special page for that category’s timeline and a function for … Read more

How to display an icon when a new post is published and then remove it when a specific time past?

Filter the content of post_class(): add_filter( ‘post_class’, function( $classes ) { if ( is_singular() ) return $classes; // now minus last mod time in seconds $diff = time() – mysql2date( ‘U’, $post->post_date ); if ( DAY_IN_SECONDS <= $diff ) $classes[] = ‘new-post’; return $classes; }); Now, in your loop, use post_class(), and you get an … Read more

Show post date on the page

the_date() is technically the template tag to do it. However it has a somewhat unusual aspect to only output once per date, so if there are multiple posts on page from same date they won’t all show it. get_the_date() is one level lower and retrieves (not outputs) a post’s date without that bit of logic.

group posts by month/date ignore years

You can use the month parameter of WP_Query to get posts by month. For example, to get all posts published on March, ignoring year: <?php $the_query = new WP_Query( ‘monthnum=3’ ); echo ‘<ul>’; while ( $the_query->have_posts() ) { $the_query->the_post(); echo ‘<li>’ . get_the_title() . ‘</li>’; } echo ‘</ul>’; wp_reset_postdata(); ?>

How to filter posts in admin by before date or by post status ‘future’?

The question pretty much got covered in another thread here. In case anyone else need anything like this I ended up using following code to hide all the posts that are over a week in the future. function hide_future_posts($where, $q) { if(is_admin() && $q->is_main_query() && !filter_input(INPUT_GET, ‘post_status’) && ( $screen = get_current_screen() ) instanceof \WP_Screen … Read more

Skip posts, but keep posts per page

Use pre_get_posts to add a meta query to the main query: function wpd_date_meta_query( $query ) { if( $query->is_post_type_archive( ‘your_post_type’ ) && $query->is_main_query() ){ $meta_query = array( array( ‘key’ => ‘Date’, ‘value’ => date(‘Ymd’), ‘compare’ => ‘>=’, ‘type’ => ‘NUMERIC’ ) ); $query->set( ‘meta_query’, $meta_query ); $query->set( ‘meta_key’, ‘Date’ ); $query->set( ‘orderby’, ‘meta_value_num’ ); $query->set( ‘order’, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)