Support

Account

Home Forums General Issues Having trouble selecting on custom fields

Solved

Having trouble selecting on custom fields

  • Hey, so, please bare with me, I’m having to fix someone’s site and I’m not really used to wordpress, but I’ve found my way here because the previous dev used your plugin and I’m trying to figure out how to use it.

    So I have one custom field called “killfeed”, which when I get that field, it returns an array of objects. That objects in that array have a property called “weapon” which is an object that has a number of properties such as “name”. So I’m trying to get the posts based on killfeed->weapon->name, where killfeed is an array of objects.

    Based on the example in your documentation, my code looks something like this right now…

    function my_posts_where($where) {
      $where = str_replace("meta_key = 'killfeed_%", "meta_key LIKE 'killfeed_%", $where);
    
      return $where;
    }
    add_filter('posts_where', 'my_posts_where');
    
    $the_query = new WP_Query([
      'numberposts' => -1,
      'post_type' => 'hamr_kill',
      'meta_query' => [
        'relation' => 'OR',
        [
          'key' => 'killfeed_%_weapon_%_name',
          'compare' => '=',
          'value' => 'Hedge Trimmer'
        ]
      ]
    ]);
    $return['the_query'] = $the_query;
    
    $return['similar_kills'] = $the_query->get_posts();
    
    return $return;

    But it’s not returning anything (and should). Any potential help on what I might be doing wrong?

  • Nevermind, sorry, turns out what I was trying to select on were “taxonomies” and “terms” and I mistook it as part of your plugin. *sigh* Carry on!

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Having trouble selecting on custom fields’ is closed to new replies.