Archived topic
A non-numeric value encountered post-meta.php on line 169 GeneratePress Theme
25 replies · Started by Charbel on January 12, 2021
Quick question please, is this PHP code snippet you shared above for WPSP Posts or for the entire site?
That's for GeneratePress only.
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/
If you've already sorted it for GeneratePress you can remove this filter from my previous code:
add_filter( 'generate_post_date_output', 'db_modified_time_stamp',15 ,2 );
But you can still reuse the db_modified_time_stamp function for WP Show Posts by adding this filter:
add_filter( 'wpsp_date_output', 'db_modified_time_stamp',15 ,2 );
Hello @Elvin,
I have added your code with add_filter( 'wpsp_date_output', 'db_modified_time_stamp',15 ,2 ); for WP Show Posts and I got an error while saving the code. Here is the final code I used.
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( 'wpsp_date_output', 'db_modified_time_stamp',15 ,2 );
Your PHP code changes were rolled back due to an error on line 138 of file wp-content/themes/generatepress_child/functions.php. Please fix and try saving again.
Uncaught ArgumentCountError: Too few arguments to function db_modified_time_stamp(), 1 passed in wp-includes/class-wp-hook.php on line 287 and exactly 2 expected in wp-content/themes/generatepress_child/functions.php:138
Stack trace:
#0 wp-includes/class-wp-hook.php(287): db_modified_time_stamp()
#1 wp-includes/plugin.php(212): WP_Hook->apply_filters()
#2 wp-content/plugins/wp-show-posts/inc/functions.php(97): apply_filters()
#3 wp-content/plugins/wp-show-posts/inc/functions.php(143): wpsp_meta()
#4 wp-includes/class-wp-hook.php(287): wpsp_add_post_meta_after_content()
#5 wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters()
#6 wp-includes/plugin.php(484): WP_Hook->do_action()
#7 /opt/bitnami/
Could you please advise?
Many Thanks @Elvin!
-Charbel
For WP Show Posts, you can:
1. Update to the latest development version: https://wpshowposts.com/wp-show-posts-1-2-0/
2. Use this filter:
add_filter( 'wpsp_post_date_show_updated_only', '__return_true' );
That will make it so only the updated date displays if it exists. If not, it will display the published date.
Thank You @Tom
I have just updated to the latest development version wp-show-posts-1.2.0-alpha.3, and then added ONLY the following filter in my PHP functions.php
add_filter( 'wpsp_post_date_show_updated_only', '__return_true' );
Do I still need to add the previous code shared by @Elvin above as well?
I have seen now that no dates are shown anymore for the WP Show Posts with updated date, I can see only the published date. Please check here: http://wpcharbelnemnomblog.northeurope.cloudapp.azure.com/
The date is removed for WP Show Posts which were updated.
Could you please advise @Tom?
Many Thanks!
Hello @Tom,
Do I still need to add the following CSS code as well?
.wp-show-posts-updated {
display: inline-block;
margin-left: 20px;
}
.wp-show-posts-updated:before {
content: "Updated on ";
}
Hello @Tom,
Now it works. The entire process is as follows:
1. Update to the latest development version: https://wpshowposts.com/wp-show-posts-1-2-0/
2. Add this filter under functions.php: add_filter( 'wpsp_post_date_show_updated_only', '__return_true' );
3. Add the following CSS code:
.wp-show-posts-updated {
display: inline-block;
}
.wp-show-posts-updated:before {
content: "Updated on ";
}
The updated date displays if it exists now, and if not, it will display the published date only.
Can we add the word Published on as well?
Thank You @Tom
Absolutely, try this:
.wp-show-posts-entry-date:before {
content: "Published on ";
}
Thanks for posting the entire process :)
Thank you @Tom, much appreciated!
It works as expected!
I have a quick question please. Last time, you shared with me the following code for non-WP Show Posts (regular blog page). Example: http://wpcharbelnemnomblog.northeurope.cloudapp.azure.com/author/charbel-nemnom/
.posted-on .updated {
display: inline-block;
}
.posted-on .updated + .entry-date {
display: none;
}
.posted-on .updated:before {
content: "Updated on ";
}
I also need to add the word Published on for posts which are not updated. What additional CSS do I need to add please?
Many Thanks @Tom!
This should do it:
.posted-on .published:before {
content: "Published on ";
}
Thank you @Tom, much appreciated!
It works...
All the best and keep up the good work!
Glad I could help :)