• Resolved torontowebdev

    (@torontowebdev)


    Hi and thank you for opening my thread,

    I am trying to display a list of users on my site which is working fine however I am trying to add a “search by” feature and things got pretty complicated.

    Here is my basic code:

    $args  = array(
      'fields' => 'all_with_meta',
      'meta_query' => array(
        array(
        'key' => 'business_city',
        'value' => 'Toronto'
        )
    ));
    $blogusers = get_users($args);

    Which works fine, HOWEVER the hard part is using another custom meta field I created that contains an Array for information 🙁

    $args  = array(
      'fields' => 'all_with_meta',
      'meta_query' => array(
        array(
        'key' => '1_area_of_acad_res',
        'value' => 'Scale of the Economy'
        )
    ));
    $blogusers = get_users($args);

    The above doesn’t display anything because the meta info reads as below (print_r)

    [1_area_of_acad_res] => Array
    (
    [0] => a:2:{i:0;s:42:”Ecological Principles in Economic Analysis”;i:1;s:24:”Other – please specify”;}
    )

    To display this information (on a detail page). I need to first unserialize [eg: unserialize($userinfo[‘1_area_of_acad_res’][0]);]

    Now how in the heck can I search this? I am now thinking it’s impossible to do this and I will need to redo my custom fields. Basically instead of a bunch of check boxes that builds an array, I make a custom meta field for each and every value and mark it as true/false… that will enable me to easily scan the db using the get_users function 🙁

    Please tell me I’m 100% wrong and this is a very easy thing to do 🙂

    Thank you so much! Also once done, I will make this into a real plugin and provide to the community because a good member list plugin cannot be found (I downloaded/purchased them all – none work to my very basic specifications/requirements)… thanks again!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter torontowebdev

    (@torontowebdev)

    Well that was easy… some more googling and this query works:

    $args  = array(
    	  'fields' => 'all_with_meta',
    	  'meta_query' => array(
    		array(
    		'key' => '1_area_of_acad_res',
    		'value' => 'My value in here',
    		'compare' => 'LIKE'
    		)
    	));

    Phew!

    Thread Starter torontowebdev

    (@torontowebdev)

    Forgot to mark as resolved… thx

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Super complex search users by custom meta data’ is closed to new replies.