WordPress.org

Ready to get started?Download WordPress

Forums

User Meta Manager
[resolved] Use without shortcodes for conditional statements? (2 posts)

  1. TechDaddyK
    Member
    Posted 1 year ago #

    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?

    http://wordpress.org/extend/plugins/user-meta-manager/

  2. President McCheese
    Member
    Plugin Author

    Posted 1 year ago #

    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
      }

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic