• Hi!

    My php isn’t amazing and I’m struggling with retrieving the value of a field in the UAM database so I can show a menu to only logged in users in the group I created called “members”.

    I got as far as this…

    <?php
    			global $wpdb;
    			$members = $wpdb->get_var(
    			"SELECT *
    			FROM  diamint_uam_accessgroups
    			GROUP BY groupname
    			ORDER BY groupname
    			LIMIT 	0, 30");
    			echo '<p>User is in group '.$members . '</p>';
    
    			 ?>

    Returns “User is in group 1” (regardless of whether or not you’re logged in – so it’s not quite what I need)

    I need to get the correct syntax for the following…

    <?php if ( $user_ID) && ( $members = "1") ?>		
    
        <?php wp_nav_menu( array('menu' => 'Members' )); ?>
    
        <?php else : ?> 	
    
         <?php wp_nav_menu( array('menu' => 'Main Nav' )); ?>
    
         <?php endif; ?>

    [Please post code snippets between backticks or use the code button.]

    help?

Viewing 5 replies - 1 through 5 (of 5 total)
  • I’m new to the user-access-manager plugin, but it may be something like this, using the UAM API:

    global $userAccessManager;
    $uamAccessHandler = $userAccessManager->getAccessHandler();
    var_dump( $userAccessManager->getUserGroups() );

    That would dump out the contents of that getUserGroups() method, which may be a jumping-off point to the next step (actually checking that the user is in the group).

    Thread Starter bathory

    (@bathory)

    Yeah that next bit is the part I really need.

    I know it’s something like this…

    <?php
    if ( is_user_logged_in()  &&  IN THE GROUP MAGIC () ) {
    	 global $wpdb;
    			$members = $wpdb->get_var(
    			"SELECT groupname
    			FROM  diamint_uam_accessgroups ");
    MAGIC GOES HERE
    			wp_nav_menu( array('menu' => 'Members' ));
    }else{
    wp_nav_menu( array('menu' => 'Main Nav' ));
    }
    ?>

    [Please post code snippets between backticks or use the code button.]

    but that’s where I’m stuck bc PHP isn’t my strong suit!

    Thanks ??

    Why don’t you learn basics of PHP with w3resource PHP tutorial.

    Thread Starter bathory

    (@bathory)

    It’s not part of my core skill set and my workload is too high to futz around when someone who does have it as a skill set could probably solve this dilemma in a few minutes.

    If I’m not mistaken, the SQL has no where clause so it will return ALL rows in the table. You are probably getting an array ($members) which is why you get the number 1. Try using ‘print_r($members)’ and see what shows up.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘IF/Else – how to show menu to members in UAM group’ is closed to new replies.