Title: Help with PHP array
Last modified: November 18, 2017

---

# Help with PHP array

 *  Resolved [peebz](https://wordpress.org/support/users/peebz/)
 * (@peebz)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/help-with-php-array/)
 * Can someone please help me edit an array so that instead of displaying posts 
   from one category ID (8), the array displays posts from either category ID 8 **
   OR** category ID 649?
 * An example is on this page, under “Agents Listings”:
    [http://bulldogrealtors.com/agents/jeff-curtis](http://bulldogrealtors.com/agents/jeff-curtis)
 * The page is currently displaying any of the Agent’s Listings (posts) with category
   ID = 8. Here is the code that works for the single category:
 * <div class=”row-agent”>
    <?php $agent_name = get_the_title(); ?> <div class=”
   none”><?php query_posts(array( ‘cat’ => 8, ‘showposts’ => 4, ‘meta_query’ => 
   array( array( ‘key’ => ‘agent’, ‘value’ => $agent_name, ‘compare’ => ‘LIKE’, )),));?
   > </div>
 * All I need to do is also show any of the Agent’s posts from category ID = 649,
   so that if the Agent has two posts with category ID 8 and two posts with category
   ID 649, the page would show all fours posts.
 * It doesn’t matter if it first shows posts from category ID 8 and only then from
   category ID 649, I just need posts with category ID 649 to show if there are 
   less than 4 posts with category 8.
 * I hope this makes sense and I really appreciate the help.
 * Best,
    P
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fhelp-with-php-array%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [Chetan Prajapati](https://wordpress.org/support/users/chetan200891/)
 * (@chetan200891)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/help-with-php-array/#post-9698161)
 * Hey [@peebz](https://wordpress.org/support/users/peebz/)
 * You can use this array.
 *     ```
       <div class=”row-agent”>
       <?php $agent_name = get_the_title(); ?>
       <div class=”none”><?php
       query_posts(array(
       ‘cat’ => '8,649',
       ‘showposts’ => 4,
       ‘meta_query’ => array(
       array(
       ‘key’ => ‘agent’,
       ‘value’ => $agent_name,
       ‘compare’ => ‘LIKE’,
       )
       ),
       ));
       ?>
       </div>
       ```
   
 * You can add categories separated by comma.
 * For more details you can check here. [https://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters](https://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters)
 *  Thread Starter [peebz](https://wordpress.org/support/users/peebz/)
 * (@peebz)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/help-with-php-array/#post-9698295)
 * Hi Chetan,
 * Thanks so much for your response. I really appreciate it.
 * First, the good news:
 * On a different template, adding the 2nd category worked like a charm. When an
   Agent has a bunch of “ID = 8” listings, they all show, but as you can see for
   this agent, who has only one “ID = 649” listing, it’s rendering perfectly:
 * [http://bulldogrealtors.com/agent-properties/?agent=Jackie%20Baker](http://bulldogrealtors.com/agent-properties/?agent=Jackie%20Baker)
 * Alas, that template uses _$args = array(_ vs. _query\_posts(array(_, as follows:
 * <div class=”property-inner-bg”>
    <?php if(isset($_GET[‘agent’]) && $_GET[‘agent’]!
   =”) { $agent_name = $_GET[‘agent’];
 *  $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
 *  $args = array(
    ‘cat’ => ‘8,649’, ‘showposts’ => 30, ‘meta_query’ => array( 
   array( ‘key’ => ‘agent’, ‘value’ => $agent_name, ‘compare’ => ‘LIKE’ ) ), ‘paged’
   => $paged ); ?>
 * Per my original question on the original template ([http://bulldogrealtors.com/agents/jeff-curtis](http://bulldogrealtors.com/agents/jeff-curtis)),
   the code you provided using _query\_posts(array(_ doesn’t break the page, but
   it seems to be losing the “Agent” key or value. Because when I inserted the code
   you provided, it displays **all** of the “8” and “649” posts regardless of the
   Agent. It didn’t control for the Agent’s name.
 * I’m not sure if this makes sense, and if it doesn’t, please don’t worry because
   I may be able to control the “8” vs. “649” by using different templates all together.
   But if it’s an easy fix for you, do let me know!
 * Thank you again, very kind of you to help.
    P
 *  [Chetan Prajapati](https://wordpress.org/support/users/chetan200891/)
 * (@chetan200891)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/help-with-php-array/#post-9698824)
 * Have you stored Agent name in “agent” meta?
 *  Thread Starter [peebz](https://wordpress.org/support/users/peebz/)
 * (@peebz)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/help-with-php-array/#post-9700156)
 * Hey Chetan,
 * Thanks again but I’m afraid it’s above my head. I’m more of a graphic designer
   than coder, just trying to change this one aspect of templates developed years
   ago.
 * (Though I will say this: I worked with .asp years ago, and it was much simpler
   to configure conditional statements!)
 * Bottom line, I’ll mickey mouse something, and sincere thanks again for your help.
 * P
 *  [Chetan Prajapati](https://wordpress.org/support/users/chetan200891/)
 * (@chetan200891)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/help-with-php-array/#post-9700347)
 * @peebbz
 * I am talking about Custom Fields [https://codex.wordpress.org/Custom_Fields](https://codex.wordpress.org/Custom_Fields).
   Without custom fields meta query will not work.
 *  Thread Starter [peebz](https://wordpress.org/support/users/peebz/)
 * (@peebz)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/help-with-php-array/#post-9704389)
 * Hey Chetan,
 * It took me all day, but I finally got it! Including new dropdown properties driven
   by the new category.
 * I just kept searching the site files, and the web, until I finally figured it
   out.
 * Thank you very much. Good Karma for you ~
 * P
 *  [Chetan Prajapati](https://wordpress.org/support/users/chetan200891/)
 * (@chetan200891)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/help-with-php-array/#post-9704391)
 * [@peebz](https://wordpress.org/support/users/peebz/) Great to see everything 
   working for you. 🙂
 *  Thread Starter [peebz](https://wordpress.org/support/users/peebz/)
 * (@peebz)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/help-with-php-array/#post-9704398)
 * Thanks again.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Help with PHP array’ is closed to new replies.

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 8 replies
 * 2 participants
 * Last reply from: [peebz](https://wordpress.org/support/users/peebz/)
 * Last activity: [8 years, 6 months ago](https://wordpress.org/support/topic/help-with-php-array/#post-9704398)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
