Support » Developing with WordPress » Replacing get_the_title() in comments.php with custom field

  • Resolved catsfoto1se


    Hi all!
    I hope this is the right forum.

    I was trying to change my comments.php, to change the get_the_title() string with get_post_custom_values(usp-custom-1) to change the default;

    thought on (title) to thoughts on (custom field 1)

    I’m getting the error: (warning) A non-numeric value encountered., I’m a newbie

Viewing 8 replies - 1 through 8 (of 8 total)
  • Subrata Sarkar


    I would suggest to read the documentation here:

    Well, it says is if the custom data field have more than one set of data, this is unique custom field that only have one string attached to each post.

    .. I’ve read, but still didn’t understand it (I did say I was a newbie?)

    • This reply was modified 1 year, 9 months ago by catsfoto1se.
    Subrata Sarkar


    Ok. Just curious, why don’t you store the value as post_meta and retrieve it using get_post_meta( $key ) function? This is more standard and recommended.

    And, can you please tell me about this custom field, how you created it and how you are storing data into it?

    Well, as I wrote, I’m a newbie, I have no idea (well, little maybe) what I’m doing.
    I’m mostly using plugins and I’m using elementor. However, the comments.php was necessary to manually edit, both because it wasn’t in my native language, and since it didn’t display the right data.

    The custom field is a normal custom field, I have no idea how it’s saved, and apparently no idea how to show it, since the command I thought would display the data, only resulted in an error, that’s why I asked what the right command would be…

    Subrata Sarkar


    Can you please share the exact code snippet you have in comments.php and what code you are trying to write?

    			$rainbowcats_comment_count = get_comments_number();
    			if ( '1' === $rainbowcats_comment_count ) {
    					/* translators: 1: title. */
    					<strong>esc_html__( 'Våra tankar om &ldquo;%1$s&rdquo;', 'rainbowcats' ),
    					'<span>' . get_post_meta(usp-custom-1) . '</span>'</strong>
    			} else {
    				printf( // WPCS: XSS OK.
    					/* translators: 1: comment count number, 2: title. */
    					esc_html( _nx( '%1$s thought on &ldquo;%2$s&rdquo;', '%1$s thoughts on &ldquo;%2$s&rdquo;', $rainbowcats_comment_count, 'comments title', 'rainbowcats' ) ),
    					number_format_i18n( $rainbowcats_comment_count ),
    					'<span>' . get_the_title() . '</span>'

    Is part of the comment.PHP

    I’ve tried remove the standard title and display a custom from current post field called usp-custom-1

    This was part of the original code:

    /* translators: 1: title. */
    					esc_html__( 'One thought on &ldquo;%1$s&rdquo;', 'rainbowcats' ),
    					'<span>' . get_the_title() . '</span>'

    And this is what I changed it to:

    `/* translators: 1: title. */
    esc_html__( ‘Våra tankar om “%1$s”’, ‘rainbowcats’ ),
    ‘<span>’ . get_post_meta(usp-custom-1) . ‘</span>’`

    • This reply was modified 1 year, 9 months ago by catsfoto1se.


    Subrata Sarkar


    get_post_meta is the function you need to use.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Replacing get_the_title() in comments.php with custom field’ is closed to new replies.