Support » Fixing WordPress » Custom Query Post

  • Resolved Rommel

    (@stanger_lei)


    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

    (@julialasarte)

    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;
    }
    Rommel

    (@stanger_lei)

    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

    (@julialasarte)

    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;
    }
    Rommel

    (@stanger_lei)

    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.