0

What is wrong with this code that the PHP will not show now that I added the css?

$args = array(       
'meta_key' => 'anniversary_date',     
 'meta_value' => 0,   
 );    
$user_query = new WP_User_Query( $args );   
 $users = $user_query->get_results();    

 foreach( $users as $user ):      
echo "<div class=\"anniversary-output\">"$user->display_name"</div>";    
 echo "<div class=\"anniversary-output\">will be celebrating their anniversary on </div>";       
echo "<div class=\"anniversary-output\">" get_user_meta( $user->ID, 'anniversary_date', true )"</div>";     
 endforeach;   
4
  • I can't seem to find your CSS. Could you point out what you changed to break any working code? Commented May 31, 2012 at 13:28
  • 1
    Also, you should have . inbetween quotes and variables to concatenate the string. Commented May 31, 2012 at 13:29
  • Yes, it's like concatenation is missing where necessary Commented May 31, 2012 at 13:31
  • Thank you, that was the problem. Commented May 31, 2012 at 13:38

3 Answers 3

1
<?php
$args = array(
    'meta_key' => 'anniversary_date',     
    'meta_value' => 0  
);

$user_query = new WP_User_Query( $args );   
$users = $user_query->get_results();    

foreach( $users as $user ) {
    echo '<div class="anniversary-output">'.$user->display_name.'</div>';
    echo '<div class="anniversary-output">will be celebrating their anniversary on</div>';       
    echo '<div class="anniversary-output">'.get_user_meta($user->ID,'anniversary_date',true).'</div>';     
}
Sign up to request clarification or add additional context in comments.

Comments

0

you have a couple of errors in your php:

The extra comma in the array & no concat .'s

<?php 
$args = array(       
'meta_key' => 'anniversary_date',     
'meta_value' => 0);    
$user_query = new WP_User_Query( $args );   
$users = $user_query->get_results();    

 foreach( $users as $user ):      
   echo "<div class=\"anniversary-output\">".$user->display_name."</div>";    
   echo "<div class=\"anniversary-output\">will be celebrating their anniversary on </div>";       
   echo "<div class=\"anniversary-output\">".get_user_meta( $user->ID, 'anniversary_date', true )."</div>";     
 endforeach; 
?>

2 Comments

some coding standards (e.g. drupal) recommends you put that extra comma
drupal is a perfect example of bad coding standards, that and wordpress, and trailing commas in arrays is perfectly valid but looks ugly and imo is bad practice, this is entirely for convenience so you can easily add another element to the array without having to first add the trailing comma to the last entry. yuk! bit.ly/LityQ3
0

I have added concatenation. Try this

echo "<div class=\"anniversary-output\">".$user->display_name."</div>";    
echo "<div class=\"anniversary-output\">will be celebrating their anniversary on </div>";       
echo "<div class=\"anniversary-output\">".get_user_meta( $user->ID, 'anniversary_date', true )."</div>";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.