• Resolved gnappo

    (@gnappo)


    Hi i have used your code and i have added excerpt and time function

    add_action('telegram_parse','telegramcustom_parse', 10, 2);
    
    function telegramcustom_parse( $telegram_user_id, $text ) {
        $plugin_post_id = telegram_getid( $telegram_user_id );
    
        if ( !$plugin_post_id ) {
            return;
        }
    
        if ( $text == '/latestnews') {
    	
    	
    	
    	$args = array( 'numberposts' => '5' );
    	$recent_posts = wp_get_recent_posts($args);
    	$return_message = '';
    	
    	foreach( $recent_posts as $recent ){
    		$return_message .=  '['.$recent["post_title"].']('.get_permalink($recent["ID"]).')'. PHP_EOL .'Posted on: '.get_the_time('F jS, Y g: ia') .PHP_EOL .PHP_EOL .get_the_excerpt($recent["ID"]) .PHP_EOL  .PHP_EOL;
    	}
    
    	wp_reset_query();
        
           telegram_sendmessage( $telegram_user_id,  $return_message);
        }
    
        return;
    }

    Problem is that get_the_time report of each post the date of last one posted not different time with each post, where i do the mistake?

    i explain better if do a new post all the post pick the data of the new post

    Thanks

    Jack

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Marco Milesi

    (@milmor)

    You can try this: [NOT TESTED]

    add_action('telegram_parse','telegramcustom_parse', 10, 2);
    
    function telegramcustom_parse( $telegram_user_id, $text ) {
        $plugin_post_id = telegram_getid( $telegram_user_id );
    
        if ( !$plugin_post_id ) {
            return;
        }
    
        if ( $text == '/latestnews') {
    	
    	
    	
    	$args = array( 'numberposts' => '5' );
    	$recent_posts = wp_get_recent_posts($args);
    	$return_message = '';
    	
    	foreach( $recent_posts as $recent ){
    		$return_message .=  '['.$recent["post_title"].']('.get_permalink($recent["ID"]).')'. PHP_EOL .'Posted on: '.$recent['post_date'].PHP_EOL .PHP_EOL .get_the_excerpt($recent["ID"]) .PHP_EOL  .PHP_EOL;
    	}
    
    	wp_reset_query();
        
           telegram_sendmessage( $telegram_user_id,  $return_message);
        }
    
        return;
    }

    If you want to change the default template, just use:
    date( 'F jS, Y g: ia', strtotime( $recent['post_date'] ) )
    instead of
    $recent['post_date']

    • This reply was modified 8 years, 1 month ago by Marco Milesi.
    Thread Starter gnappo

    (@gnappo)

    thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get_the_time’ is closed to new replies.