Amesey
Amesey

Reputation: 852

test condition of advance custom field is true in WordPress

i'm trying to test if a post has either of two conditions of a custom field. i'm using the plugin advanced custom types. i've created a field called visibility whereby the administrator can select whether a post of page is public or private. this will then display a custom message depending on whether the user is logged in and the condition of the field. However with my code below the condition is always returned as public even if the field is set to private on a post.

<?
$visibility = get_field('visibility');

if($visibility='public'){ 


get_template_part( 'content', 'single' ); 


} else if ($visibility='private') { ?>

<p>You must be logged in to view this post</p>

<?php } ?>

Upvotes: 0

Views: 168

Answers (1)

Ivan Han&#225;k
Ivan Han&#225;k

Reputation: 2306

Shorty, take a look at a difference between = and ==.

You are assigning, and therefore your first condition is always true.

For comparing use always == or ===, pay a great deal of attention to that.

Upvotes: 1

Related Questions