• What is wrong here? I followed some models already working but…

    //prova display price2 con IF
    $display_price2 = get_the_author_meta( '2_periodo', $post->post_author ). ' - ' . get_post_meta( $post->ID, "function_prezzo_secondo", true ). ;
    
    if ( ! empty( $display_price2)) {
    
    $display_price2='<div class="listino_prezzi">'. $display_price2 .'</div>';
    //fine prova
    
    
Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    There’s an extra . operator at the end of the first assignment line that doesn’t belong. There could be other issues, but looking at code out of context makes it difficult to know.

    Do you have WP_DEBUG defined as true in wp-config.php? Doing so will display error messages right on the page. Good for development, bad for production. The message ‘unexpected token “;” in path/filename on line nnn‘ would give you a good clue on where and what to look for. Meaning something before the ; is not as it should be. In this case it is immediately before. In other cases it can even be on a preceding line. Error messages are where PHP realized there is an error, not necessarily where the error really is.

    We’re happy to help you resolve coding problems when you’re unable to, but resolving on your own when possible will get your code working sooner 😉

    Thread Starter sacconi

    (@sacconi)

    besides the . I forgot the final bracket 🙂

    I’m trying also to put a <strong>, I’ve tryed a lot of times but..nothing..here is my last try:

    $display_price2 = get_the_author_meta( '2_periodo', $post->post_author ). ' ' '<strong>'. get_post_meta( $post->ID, 'function_prezzo_secondo', true ). '</strong>' ' &euro;'.'/ sett.' ;
    if ( ! empty( $display_price2)) {
    $display_price2='<div class="listino_prezzi">'. $display_price2 .'</div>';
    }
    
    Moderator bcworkz

    (@bcworkz)

    Too may quotes 🙂 And unnecessary concatenation, though concatenation would be syntactically correct, it’s not necessary.
    $display_price2 = get_the_author_meta( '2_periodo', $post->post_author ). '<strong>'. get_post_meta( $post->ID, 'function_prezzo_secondo', true ). '</strong> &euro;/ sett.';
    untested, but should be right… gotta run right now.

    Thread Starter sacconi

    (@sacconi)

    2 quotes were for displaying a blank space…just before '<strong>'

    Moderator bcworkz

    (@bcworkz)

    Include the blank space with the strong tag ' <strong>'. While you could have used a another . operator to add the space, you should avoid concatenating static strings together. Instead combine the strings into a single element. It’s not technically wrong to concatenate static strings, but it adds needless complexity and makes code more difficult to read.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Function not working’ is closed to new replies.