• Resolved TechDaddyK

    (@techdaddyk)


    Trying to use the meta data to restrict access. Found this code, on author’s website, to retrieve the current user’s meta info:

    global $current_user;
    $data = get_user_meta($current_user->ID, ‘my_key’);

    However, when I try to echo the $data variable (using each of my custom keys), I get “Array” instead of the expected output.

    I’d happily use a shortcode instead, but from what I can tell, you can’t really use conditional statements. I need to display items with specific tags to different groups of people that potential match more than one meta key value.

    Any suggestions on how to use this plugin without the shortcodes?

    https://www.ads-software.com/extend/plugins/user-meta-manager/

Viewing 1 replies (of 1 total)
  • Plugin Author Jason Lau

    (@jason-lau)

    Below are a couple PHP methods you can use to test User Meta Manager data.

    • umm_value_contains($key, $search_for, $exact, $user_id)
      Test if a meta value contains a string.

      $key (string) The meta key to test.
      $search_for (string) The string to search for.
      $exact (boolean) Optional exact match. Default is case-insensitive.
      $user_id (number) Optional user ID. Default is the current user.

      Example:

      $meta_key_to_search = "my_key";
      $string_to_search_for = "abc";
      $case_sensitive = true;
      if(umm_value_contains($meta_key_to_search, $string_to_search_for, $case_sensitive)){
          // Exact match for abc
      } else {
          // No exact match for abc
      }

    • umm_value_is($key, $search_for, $user_id)
      Test if a meta value is an exact match.

      $key (string) The meta key to test.
      $search_for (string) The string to match.
      $user_id (number) Optional user ID. Default is the current user.

      Example:

      $meta_key_to_test = "my_key";
      $string_to_match = "abc";
      if(umm_value_is($meta_key_to_test, $string_to_match)){
          // Exact match for abc
      } else {
          // No exact match for abc
      }

Viewing 1 replies (of 1 total)
  • The topic ‘Use without shortcodes for conditional statements?’ is closed to new replies.