[Resolved] A non-numeric value encountered post-meta.php on line 169 GeneratePress Theme

Home Forums Support [Resolved] A non-numeric value encountered post-meta.php on line 169 GeneratePress Theme

Home Forums Support A non-numeric value encountered post-meta.php on line 169 GeneratePress Theme

Viewing 15 posts - 1 through 15 (of 26 total)
  • Author
    Posts
  • #1615847
    Charbel

    Hello Support Team,

    Hope you are doing well.

    I am working with codeable.io to set up my new GeneratePress Theme with Dispatch Template.

    We have come across a strange issue in regards to the blog/author-page.
    Check it here please (staging site): http://wpcharbelnemnomblog.northeurope.cloudapp.azure.com/author/charbel-nemnom/

    You can see the following error on every article:

    Warning: A non-numeric value encountered in /opt/bitnami/apps/wordpress/htdocs/wp-content/themes/generatepress/inc/structure/post-meta.php on line 169

    Your help is highly appreciated on solving this issue at your earliest.

    Many Thanks!
    -Charbel

    #1615920
    David
    Staff
    Customer Support

    Hi there,

    has there been any modifications made to the parent theme files?

    Here is line 169 in the post-meta.php:

    https://github.com/tomusborne/generatepress/blob/e030f57d2c26991074a6868265737424dac567d0/inc/structure/post-meta.php#L169

    Can you check to make sure this has not been edited or any of the code around it.

    #1615945
    Charbel

    Thank you @David for your quick response

    Please note that we did not change or modify any of these.

    Here is line 169 in the post-meta.php from my current GeneratePress Theme installation:

    $published_time = get_the_time( 'U' ) + 1800;

    Please advise?

    Thank You!

    #1615950
    David
    Staff
    Customer Support

    Do you have any custom functions that changes the post meta – i see you have a non standard meta layout that also includes reading time – How is that added?

    #1615959
    Charbel

    Hello @David,

    Yes, I am using Child Theme and I have added Reading Time Estimate in my functions.php

    Here is the code that I am using in my functions.php:

    /***** Adding Reading Time Blog *****/
    function tu_estimated_reading_time() {
        $post = get_post();
        $content = $post->post_content;
        $wpm = 300; // How many words per minute.
        $clean_content = strip_shortcodes( $content );
        $clean_content = strip_tags( $clean_content );
        $word_count = str_word_count( $clean_content );
        $time = ceil( $word_count / $wpm );
        return $time . ' minutes';
    }
    add_filter( 'generate_post_date_output', function( $output ) {
        $output .= '<div class="read-time">Reading time: ' . tu_estimated_reading_time() . '</div>';
        return $output;
    } );

    Here is another function, I am using for the date published/modified:

    /***** Adding Last Modified Date Blog *****/
    function et_last_modified_date_blog( $the_date ) {
        if ( 'post' === get_post_type() ) {
            $the_time = get_post_time( 'His' );
            $the_modified = get_post_modified_time( 'His' );
            $published =  sprintf( __( '%s', 'Divi' ), esc_html( get_post_time( 'M j, Y' ) ) );
    		$last_modified =  sprintf( __( 'Updated on %s', 'Divi' ), esc_html( get_post_modified_time( 'M j, Y' ) ) );
            $date = $the_modified !== $the_time ? $published . ' | ' .  $last_modified : $published;
            return $date;
        }
    }
    add_action( 'get_the_date', 'et_last_modified_date_blog' );
    add_action( 'get_the_time', 'et_last_modified_date_blog' );

    Please note that I’ve commented the function, and the error is the same.

    Please advise?

    Thank You!

    #1615966
    Charbel

    Hello @David,

    I found the issue. It’s related to the Date published/modified function below:

    /***** Adding Last Modified Date Blog *****/
    function et_last_modified_date_blog( $the_date ) {
        if ( 'post' === get_post_type() ) {
            $the_time = get_post_time( 'His' );
            $the_modified = get_post_modified_time( 'His' );
            $published =  sprintf( __( '%s', 'Divi' ), esc_html( get_post_time( 'M j, Y' ) ) );
    		$last_modified =  sprintf( __( 'Updated on %s', 'Divi' ), esc_html( get_post_modified_time( 'M j, Y' ) ) );
            $date = $the_modified !== $the_time ? $published . ' | ' .  $last_modified : $published;
            return $date;
        }
    }
    add_action( 'get_the_date', 'et_last_modified_date_blog' );
    add_action( 'get_the_time', 'et_last_modified_date_blog' );

    I commented this function and the issue is resolved.

    Could you please recommend what is the best approach or code to use to accomplish the same?

    Thank You!
    -Charbel

    #1615972
    Charbel

    I have also WP Debug set to True to debug this issue.

    #1616375
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Can you explain a bit about what you’re wanting that function to do?

    Right now it’s making it so the get_the_time() function isn’t returning a unix timestamp (which is a number). So the + is adding a non-number (because of the filter) to a number.

    We may be able to offer a different solution to that filter if we know the needed result 🙂

    #1616560
    Charbel

    Hello @Tom,

    Thank you for your kind support! Hope you are doing well.

    I have two functions: The reading estimate time is working fine, so we can disregard this function.

    I migrated from MH Magazine Theme to a GeneratePress Dispatch Theme, so I moved my date function.
    The function below is for showing the published date, as well as the updated date across my entire site with the following format: Jan 4, 2021 | Updated on Jan 4, 2021

    Author Page: http://wpcharbelnemnomblog.northeurope.cloudapp.azure.com/author/charbel-nemnom/
    Homepage for WPSP Posts: http://wpcharbelnemnomblog.northeurope.cloudapp.azure.com
    Articles: http://wpcharbelnemnomblog.northeurope.cloudapp.azure.com/export-all-nsg-rules-from-all-azure-subscriptions-with-powershell/

    /***** Adding Last Modified Date Blog (Old Code) *****/
    // A non-numeric value encountered post-meta.php on line 169 //
    function et_last_modified_date_blog( $the_date ) {
        if ( 'post' === get_post_type() ) {
            $the_time = get_post_time( 'His' );
            $the_modified = get_post_modified_time( 'His' );
            $published =  sprintf( __( '%s', 'Divi' ), esc_html( get_post_time( 'M j, Y' ) ) );
    		$last_modified =  sprintf( __( 'Updated on %s', 'Divi' ), esc_html( get_post_modified_time( 'M j, Y' ) ) );
            $date = $the_modified !== $the_time ? $published . ' | ' .  $last_modified : $published;
            return $date;
        }
    }
    add_action( 'get_the_date', 'et_last_modified_date_blog' );
    add_action( 'get_the_time', 'et_last_modified_date_blog' );

    The problem with that function, it’s throwing the error below on the author page (only):
    http://wpcharbelnemnomblog.northeurope.cloudapp.azure.com/author/charbel-nemnom/
    However, the published and updated date are still showing (e.g. Jan 4, 2021 | Updated on Jan 4, 2021) as you can see. The error is showing because I have enabled WP Debug set to True to debug another issue, then I found that the function above is causing it.
    Warning: A non-numeric value encountered in /opt/bitnami/apps/wordpress/htdocs/wp-content/themes/generatepress/inc/structure/post-meta.php on line 169

    What do you recommend, and what is the best approach to use so we can show both the published + updated date for readers and Google?

    Thank You @Tom!
    -Charbel

    #1617449
    Tom
    Lead Developer
    Lead Developer

    This method is likely better than using the function: https://docs.generatepress.com/article/show-the-updated-post-date/

    However, in my experience, Google will only display a date in search results if it’s the only date on the page.

    Let me know 🙂

    #1617489
    Charbel

    Thank You @Tom,

    I have implemented the method you noted above entirely including the Show the “Updated” Post Date in Header Element: https://docs.generatepress.com/article/show-the-updated-post-date/

    I was able to show the updated date for the Author blog Page here: http://wpcharbelnemnomblog.northeurope.cloudapp.azure.com/author/charbel-nemnom/

    For the single article(s), I added the Published on {{post_date}} | Updated on [modified_date] under Elements | Single Post: http://wpcharbelnemnomblog.northeurope.cloudapp.azure.com/export-all-nsg-rules-from-all-azure-subscriptions-with-powershell/

    However, the updated date is not showing on the Homepage for WPSP Posts, the published date is displayed: http://wpcharbelnemnomblog.northeurope.cloudapp.azure.com

    In between, I am using WPSP Pro Edition. Could you please advise on how can I show the updated date for WPSP Posts as well?

    Thank You @Tom

    #1618840
    Tom
    Lead Developer
    Lead Developer

    For Show Posts, you can do this:

    .wp-show-posts-updated {
        display: inline-block;
        margin-left: 20px;
    }
    
    .wp-show-posts-updated:before {
        content: "Updated on ";
    }
    #1618927
    Charbel

    Thank you @Tom, much appreciated!

    That’s works, however, the display is not aligned properly when the month name is long such as November.
    In this case, the date on Show Posts is showing on 2 lines as follows (Published + Updated):

    November 24, 2020
    Updated on November 24, 2020

    You can have a quick look here: http://wpcharbelnemnomblog.northeurope.cloudapp.azure.com/

    Is there a way to show either date (published on OR updated on), so if the article was updated, we will show ONLY Updated on November 24, 2020, and if the article was not updated, we will show ONLY Published on December 21, 2020

    Thank You @Tom

    #1619452
    Elvin
    Staff
    Customer Support

    Hi,

    Is there a way to show either date (published on OR updated on), so if the article was updated, we will show ONLY Updated on November 24, 2020, and if the article was not updated, we will show ONLY Published on December 21, 2020

    You can try this PHP snippet:

    function db_modified_time_stamp( $output, $time_string ) {
    	$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Published on %2$s at %5$s</time> ';
    	
    	if ( get_the_modified_time( 'U' ) > get_the_time( 'U' ) ) {
    		$time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">Updated on %4$s at %6$s</time>  
    			<time class="entry-date published" datetime="%1$s" itemprop="datePublished" style="display:none;">Published on %2$s at %5$s</time>';
    	}
    
    	$time_string = sprintf( $time_string,
    		esc_attr( get_the_date( 'c' ) ),
    		esc_html( get_the_date( 'F j, Y' ) ),
    		esc_attr( get_the_modified_date( 'c' ) ),
    		esc_html( get_the_modified_date( 'F j, Y' ) ),
    		esc_html( get_the_date( 'g:i A' ) ),
    		esc_html( get_the_modified_date( 'g:i A' ) )
    	);
    
    	return sprintf( '<span class="posted-on">%1$s</span>', // WPCS: XSS ok, sanitization ok.
    		sprintf( '%1$s',
    			$time_string
    		)
    	);
    }
    
    add_filter( 'generate_post_date_output', 'db_modified_time_stamp',15 ,2 );

    This PHP snippet checks if the post is modified and then displays its modified date instead of the published date.

    A wise man once said:
    "Have you cleared your cache?"

    #1619477
    Charbel

    Thank you @Elvin,

    Quick question please, is this PHP code snippet you shared above for WPSP Posts or for the entire site?

    I have already the published date and/or modified date works fine for articles and author page.
    I have implemented the method noted here: https://docs.generatepress.com/article/show-the-updated-post-date/

    I need to fix WPSP Posts date only. Could you please confirm?

    Thank You!

Viewing 15 posts - 1 through 15 (of 26 total)
  • You must be logged in to reply to this topic.