Query events post type after current date and timezone

date() PHP functions returns the value of time() PHP functions in the specified format. time() use server local time. If you want to get date/time based of WordPress configuration, you could use current_time(), a WordPress function, instead of native PHP functions. // ‘timestamp’ = Unix Timestamp or ‘U’ PHP time format $current_time = current_time( ‘timestamp’ … Read more

Adding fields to attachment – only shows when inserting new attachments

Okay I think I have it, you need to add a matching filter to attachment_fields_to_save to save the new field (say as post meta to the attachment.) add_filter( ‘attachment_fields_to_save’, ‘save_some_custom_field’, 10, 2 ); function save_some_custom_field($post, $attachment) { $attachid = $post[‘ID’]; // yes this is actually an array here update_post_meta($attachid,’someCustom’,$attachment[‘someCustom’]); } Then you would add to … Read more

Metabox value for post loop?

Thanks guys.I did it with WP_Meta_Query (https://codex.wordpress.org/Class_Reference/WP_Meta_Query) Solution: <?php $query = new WP_Query( array( ‘meta_key’ => ‘j4cob_yaz_ayarlar_show_on_slider_’, ‘meta_value’ => ‘show-on-slider’, ‘posts_per_page’ => 6 ) ); ?> <?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?> . Loop . <?php endwhile; wp_reset_postdata(); else : ?> <p><?php _e( ‘Sorry, no posts matched your … Read more

Wrap group of wp query posts to parent div by date/year

This cannot be done only by querying database. Firstly, you have to iterate through all items and create array of posts grouped by dates. $args = array( ‘posts_per_page’ => -1, ‘post_type’ => ‘event’, ‘meta_key’ => ‘event_date’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’ ); $wpquery = new WP_Query($args); $posts = $wpquery->get_posts(); $ordered_posts = array(); foreach ($posts … Read more

Post date on Custom field

There is a hook called save_posts so you need to hook a function into that post like add_action(‘save_posts’,’store_date’); function store_date(){ if(get_post_type()==’post’){ $month=get_the_date(‘M’); $year=get_the_date(‘Y’); update_post_meta(get_the_ID(),’month-field’,$month); update_post_meta(get_The_ID(),’year-field’,$year); } } This should be all you need Here are additonal links to save_posts and update_post_meta