Random meta field from specific custom post type
You could pull it directly form the database: global $wpdb; $random_photo = $wpdb->get_var(“SELECT meta_value FROM wp_postmeta WHERE meta_key like ‘single_photo’ ORDER BY RAND()”);
You could pull it directly form the database: global $wpdb; $random_photo = $wpdb->get_var(“SELECT meta_value FROM wp_postmeta WHERE meta_key like ‘single_photo’ ORDER BY RAND()”);
There’s no reason you can’t call add_meta_box() twice in a row and use the same function to display it both times; just change the $post_type parameter. Example foreach ( array ( ‘post’, ‘page’ ) as $post_type ) { add_meta_box( ‘your_id’, ‘your title’, ‘your_callback’, $post_type ); }
wp_trash_post and trashed_post – from source: function wp_trash_post($post_id = 0) { if ( !EMPTY_TRASH_DAYS ) return wp_delete_post($post_id, true); if ( !$post = wp_get_single_post($post_id, ARRAY_A) ) return $post; if ( $post[‘post_status’] == ‘trash’ ) return false; do_action(‘wp_trash_post’, $post_id); add_post_meta($post_id,’_wp_trash_meta_status’, $post[‘post_status’]); add_post_meta($post_id,’_wp_trash_meta_time’, time()); $post[‘post_status’] = ‘trash’; wp_insert_post($post); wp_trash_post_comments($post_id); do_action(‘trashed_post’, $post_id); return $post; }
Use following code after the loop: $month_num = get_the_date(‘n’); $month_txt = get_the_date(‘F’); $year = get_the_date(‘Y’); // change ‘posts_per_page’ to any value you need, ‘-1’ means ‘all’ query_posts( ‘posts_per_page=-1&monthnum=’.$month_num.’&year=”.$year ); echo “<p class=””>Archived in ‘.$month_txt.’, ‘.$year.'</p>’; echo ‘<ul>’; while ( have_posts() ) : the_post(); echo ‘<li><a href=”‘.get_permalink().'”>’.get_the_title().'</a></li>’; endwhile; echo ‘</ul>’; wp_reset_query(); It’s not tested, but you … Read more
You’d need to set up an additional custom field and update it whenever the user changes or updates the original custom field.
On which hook of WP init this code part? $user_id – why and from how is this var value? update_post_meta() will use the post ID, see Codex.
The WordPress “gallery” functionality partly depends on the attachment of the media to the post via the post_parent column. Specifying IDs in your shortcode allows you to include images in your gallery that aren’t necessarily “attached” to your post — that is to say, not uploaded from within your post or page. This flexibility allows … Read more
Answering my own question, as suggested in my edit I’ve had to use the following meta_query array to query the posts: ‘meta_query’ => array( array( ‘key’ => ‘country’, ‘compare’ => ‘LIKE’, ‘value’ => ‘”‘ . get_the_ID() . ‘”‘ ) )
I fixed this by adding: global $post; More specific: I can’t explain why this works, that’s beyond my WordPress skills, but I added it right after the start of the query, so the code looks like this: <?php global $post; $loop = new WP_Query( array( ‘post_type’ => ‘kurs’, ‘posts_per_page’ => ‘5’, ‘meta_key’ => ‘dato’, ‘meta_value’ … Read more
There’s the get_post_meta() function to retrieve those data. So basically, you’d write a function in your functions.php file (or in a custom plugin – take “Hello Dolly” as example) and hook it. <?php /* Plugin Name: (#66495) »kaiser« Headway Title Button */ function wpse66495_headway_title_button() { return printf( ‘<div class=”title-btn”><a href=”https://wordpress.stackexchange.com/questions/66495/%s” alt=”https://wordpress.stackexchange.com/questions/66495/%s”><img src=”%s /></a></div>’ ,get_post_meta( get_the_ID(), … Read more