WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom Query Post (5 posts)

  1. Rommel
    Member
    Posted 2 years ago #

    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

  2. popper
    Member
    Posted 2 years ago #

    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;
    }
  3. Rommel
    Member
    Posted 2 years ago #

    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

  4. popper
    Member
    Posted 2 years ago #

    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;
    }
  5. Rommel
    Member
    Posted 2 years ago #

    yeah!

    Thanks a lot! My experiment is success! Thanks so much for you for helping :)

    Thanks,
    Rommel

Topic Closed

This topic has been closed to new replies.

About this Topic