0

I am trying to make a WordPress shortcode a little different then it is working now and that is when there is any value filled in then the object will be visible.

I have now this:

function open_books( $atts ) {
    $a = shortcode_atts( array(
        'amount' => 5
    ), $atts );

    $args = array(
        'posts_per_page'    => intval( $a['amount'] ),
        'post_type'         => 'all_books',
    );
    $the_query = Books::search()->where('bookdate', '2019-03-30 11:00:00');

   if ( $the_query->have_posts() ) {
        $ret = '<div id="entity-items">';
        $i = 0;
        while ( $the_query->have_posts() ) {
            if( $i < $a['amount'] ) {
                $i++;
                $the_query->the_post();
                $ret .= Books::template('item')->cache();
            }
        }
    }
    $ret .= '</div>';
    wp_reset_postdata();

    return $ret;
}
add_shortcode( 'open_books', 'open_books' );

But this is online showing the object with that specific date but i want that the query will show all objects that haves a date.

Maanstraat
  • 1,241
  • 7
  • 34
  • 63
  • instead of using where('bookdate', '2019-03-30 11:00:00') use where('bookdate', IS NOT NULL) – Gaurav Mar 09 '19 at 11:22
  • @GauravS i then get a error 500. $the_query = Books::search()->where('bookdate', IS NOT NULL); – Maanstraat Mar 09 '19 at 11:25
  • @GauravS Of course, `IS NOT NULL` would need to be quoted when being passed to the function. We might assume that `where()` is going to put a `=` between the two parameters when building the clause (I don't know, I don't Wordpress). – mickmackusa Mar 09 '19 at 12:47

0 Answers0