Title: Custom Query Post
Last modified: August 20, 2016

---

# Custom Query Post

 *  Resolved [Rommel](https://wordpress.org/support/users/stanger_lei/)
 * (@stanger_lei)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/custom-query-post/)
 * Hi,
 * Please help 🙁
 * I want to work in this one. It gets me some error in the output. I put this on
   the functions. It is fine.
 *     ```
       function display_exhibitor_logo($custom_query){
       	$html = '';
       	while ( $custom_query->have_posts() ) : $custom_query->the_post();
       		$attr['title'] = $attr['alt'] = get_the_title();
       		$html .= '<li class="exhibitor-home-img"> '.get_the_post_thumbnail(get_the_ID(), 'exhibitor-img2', $attr ).'</li>';
       	endwhile;
       	return $html;
       }
       ```
   
 * But..
 * I want to add a custom field that when exists, it can add a style=”display:none”
   to hide.
 *     ```
       function display_exhibitor_logo($custom_query){
       	$html = '';
       	while ( $custom_query->have_posts() ) : $custom_query->the_post();
       		$attr['title'] = $attr['alt'] = get_the_title();
       		$html .= '<li class="exhibitor-home-img" '.get_post_meta($post->ID, 'checked', true)  ) ? 'style="display:none"' : '').'> '.get_the_post_thumbnail(get_the_ID(), 'exhibitor-img2', $attr ).'</li>';
       	endwhile;
       	return $html;
       }
       ```
   
 * It gives me some error in the output when I add the get post meta.
 * Please help.
 * Thanks,
    Rommel

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

 *  [popper](https://wordpress.org/support/users/julialasarte/)
 * (@julialasarte)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/custom-query-post/#post-2848826)
 * You have some issues with your parenthesis. Add parenthesis to your ternary selector,
   so it’s evaluated in the right order:
 *     ```
       function display_exhibitor_logo($custom_query){
           $html = '';
           while ( $custom_query->have_posts() ) : $custom_query->the_post();
               $attr['title'] = $attr['alt'] = get_the_title();
               $html .= '<li class="exhibitor-home-img" '.(get_post_meta($post->ID, 'checked', true) ? 'style="display:none"' : '').'> '.get_the_post_thumbnail(get_the_ID(), 'exhibitor-img2', $attr ).'</li>';
           endwhile;
           return $html;
       }
       ```
   
 *  Thread Starter [Rommel](https://wordpress.org/support/users/stanger_lei/)
 * (@stanger_lei)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/custom-query-post/#post-2848881)
 * Hi popper,
 * Thanks for your response! The error is gone. But my function didn’t work.
    I 
   am trying to add get_post_meta so if the value exist, it can add a style=”” or
   a css class.
 * Please help 🙁
 * Thanks,
    Rommel
 *  [popper](https://wordpress.org/support/users/julialasarte/)
 * (@julialasarte)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/custom-query-post/#post-2848921)
 * Try:
 *     ```
       function display_exhibitor_logo($custom_query){
           $html = '';
           while ( $custom_query->have_posts() ) : $custom_query->the_post();
               $attr['title'] = $attr['alt'] = get_the_title();
               $html .= '<li class="exhibitor-home-img" '.(get_post_meta(get_the_ID(), 'checked', true) ? 'style="display:none"' : '').'> '.get_the_post_thumbnail(get_the_ID(), 'exhibitor-img2', $attr ).'</li>';
           endwhile;
           return $html;
       }
       ```
   
 *  Thread Starter [Rommel](https://wordpress.org/support/users/stanger_lei/)
 * (@stanger_lei)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/custom-query-post/#post-2848934)
 * yeah!
 * Thanks a lot! My experiment is success! Thanks so much for you for helping 🙂
 * Thanks,
    Rommel

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

The topic ‘Custom Query Post’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [Rommel](https://wordpress.org/support/users/stanger_lei/)
 * Last activity: [13 years, 11 months ago](https://wordpress.org/support/topic/custom-query-post/#post-2848934)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
