I am having a problem with an if statement which I have now tested many times over.
$user_query = new WP_User_Query( array( 'role' => 'Subscriber' ) );
if ( !empty( $user_query->results ) ) {
foreach ( $user_query->results as $user ) {
echo $user->province . '<br/>'; // this outputs the province as expected, i.e. Free State
if ($user->province == 'Free State') { // This does not return true, even though the echo above works
echo '<strong>' . $user->company_name . '</strong> <br/>';
echo $user->town. '<br/>';
echo $user->province. '<br/>';
}
} else {
echo 'There are currently no photographers for this region.';
}
}
I basically only wanting to show photographers in a certain province.
Many thanks.
Try changing this:
to:
First I would make sure the output on the echo is exactly as you suspect by wrapping it in
<pre>
tags, then viewing source on the front end to make sure there are no other special characters involved.I notice that this post, http://tommcfarlin.com/wp_user_query/ uses
$user_query->get_results();
instead of$user_query->results;
maybe give that a try?I’ve always had problems with doing if statements by name and where possible use id’s instead. But it doesn’t sound like that is possible here :/