Home Forums General Issues Advanced Post-Type Filtering with Meta


Advanced Post-Type Filtering with Meta

  • So, I’ve created my own Sports tracking on the backend with ACF-Pro and I need to display all of the scores for a given team, in a given sports, during a given season.

    I can’t get my meta-query to show scores for all games (home and away), only home or away depending on the order of my query:

    'meta_query' => array ( 
          'relation' => 'OR', 
          array ( 'key' => 'game_home_team', 'value' => $team_id ),
          array ( 'key' => 'game_away_team', 'value' => $team_id ) 
      array ( 
          'relation' => 'AND', 
          array ( 'key' => 'game_season', 'value' => $season ),
          array ( 'key' => 'game_sport', 'value' => $sport ) 

    With this code, only away games are shown. If I swap the OR arrays around to put away first, then only home games are shown.

    I could use some help, or a link to something that better explains advanced meta-queries in WordPress because I’m confused.


  • Okay, I simplified it to just:

    'meta_query' => array( 'relation' => 'OR', 
                       array( 'key' => 'game_home_team', 'value' => $team_id ),
                       array( 'key' => 'game_away_team', 'value' => $team_id ) 

    Ignoring the sport and season. And I am still only getting home or away games depending on the order of the keys.

  • Okay… So I’m an idiot… The code actually works, but I did not specify HOW MANY posts I wanted, so WordPress just kept giving me 5, which just happens to be the number of games.

    Adding 'posts_per_page' => -1 fixed my problem.

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

The topic ‘Advanced Post-Type Filtering with Meta’ is closed to new replies.