Tell us what you are trying to do? I'm building a membership site using the Ultimate Membership Pro (UMP) plugin. With this plugin, every user can have more than one membership level.
Now, I need to display some post content by the author post membership level(s).
To get the post author level(s), I have created a shortcode:
The shortcode return the levels value in array mode (1,2,3,5, ecc... but it could be 1,5,2,3, ecc...).
Now, for a specific post author level, the user can see relative content, for example:
with the silver level, the user can see the post author phone number;
with the gold level, the user can see the post author email address;
with the diamond level, the user can see the post author phone number and email address;
but the post author can have silver and gold level, and the user can see the post author phone number and email address, same as diamond level.
What should I do to set the conditional logic using the array values?
Is there any documentation that you are following? I don't know
Is there a similar example that we can see? I don't know
Hi,
I have tried to use the in_array() function but I think that it don't work fine, I think that the array I want to pass into in_array() function contains object, but I'm not shure...
I have tried to use this custom code, but it not return me any message
add_shortcode( 'nome-autore', 'nome_autore' );
function nome_autore()
{
$author_levels = do_shortcode("[livello-autore]"); //the shortcode return values as 1,3,5,2,4, ecc...
if (in_array('2', $author_levels) or in_array('3', $author_levels) or in_array('4', $author_levels) or in_array('5', $author_levels) or in_array('6', $author_levels) or in_array('7', $author_levels) or in_array('8', $author_levels) or in_array('9', $author_levels) or in_array('10', $author_levels))
{
return "L'autore è abbonato";
}
elseif (in_array('0', $author_levels) or in_array('1', $author_levels))
{
return "L'autore NON è abbonato";
}
}
Also, I have tried to use this custom code, but the only value return is 0
add_shortcode( 'abbonamento', 'abbonamento' );
function abbonamento()
{
//$author_levels = do_shortcode("[livello-autore]");
//return $author_levels;
//$abbonamento='false';
$author_id = get_the_author_meta( 'ID' );
$level_array =array();
$author_levels='';
$level_array = Ihc_Db::get_user_levels($author_id);
$i=1;
foreach ($level_array as $key => $object){
$author_levels .= $key;
if ($i < count($level_array)) $author_levels .=', ';
$i++;
if (in_array('2', $author_levels, TRUE) or in_array('3', $author_levels, TRUE) or in_array('4', $author_levels, TRUE) or in_array('5', $author_levels, TRUE) or in_array('6', $author_levels, TRUE) or in_array('7', $author_levels, TRUE) or in_array('8', $author_levels, TRUE) or in_array('9', $author_levels, TRUE) or in_array('10', $author_levels, TRUE))
{
$abbonamento='1';
}
else {$abbonamento='0';}
}
return $abbonamento;
}
What could be a solution to return the correct value?
Can you please share access details as well as where you added the above code you shared and problem URL.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
Can you please tell me where exactly with what field you are using the custom shortcode you created?
=> lien caché
In addition to that, if you added the code to theme's functions.php file you need to send me FTP access details so that I can access the code you added.
I have set the next reply to private which means only you and I have access to it.
ok - I got it and now I want more information. Do you mean that if the author level is equal to 1 then you want to return 0 and for all other author level you want to return 1?
For now if the author level is equal to '', 0 and 1 I want return 0, and for all other author level I want to return 1.
The author levels are added dinamically, and is probably that other levels that I could add, them could return 0.