Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Schedule Cron Job Event
- // Custom Cron Schedule Interval
- function auto_post_job_function_own( $schedules ) {
- $schedules['post-change-24-hour'] = array(
- 'interval' => 12, // 86400
- 'display' => __( 'Custom Label' )
- );
- return $schedules;
- }
- add_filter( 'cron_schedules', 'auto_post_job_function_own' );
- if ( ! wp_next_scheduled( 'auto_post_job_function_hook' ) ) {
- wp_schedule_event( current_time( 'timestamp' ), 'post-change-24-hour', 'auto_post_job_function_hook' );
- }
- add_action('auto_post_job_function_hook', 'auto_post_job_function');
- function auto_post_job_function() {
- $args = array(
- 'post_type' => 'post',
- 'orderby' => 'rand',
- 'posts_per_page' => 1,
- );
- $the_query = new WP_Query( $args );
- if ( $the_query->have_posts() ) {
- $string .= '<ul>';
- while ( $the_query->have_posts() ) {
- $the_query->the_post();
- $string .= '<li><a href="'. get_permalink() .'">'. get_the_title() .'</a></li>';
- }
- $string .= '</ul>';
- /* Restore original Post Data */
- wp_reset_postdata();
- } else {
- $string .= 'no posts found';
- }
- return $string;
- };
- add_shortcode( 'rand_post', 'auto_post_job_function' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement