• Resolved David Cole

    (@coleds)


    I’ve setup pods as per instructed on the website, but I am getting nothing in return value:

    
    $params = array(
    	'where' => 'my_field.meta_value LIKE "%'.$date_format.'%"',
    );
    $pods = pods('events', $params);
    if (0 < $pods->total()) {
    	while ($pods->fetch()) {
    		echo '<p>'.$pods->field('name').'</p>';
    	}
    }
    

    $date_format is 2021-05-31 same as the value in the database along with many other variations all of which do not show when doing the above search. Total always returns zero. Please advise.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @coleds

    If you put the date format like this it will only fetch the posts on that particular date. You cannot query on a format of a date, only the content of a meta value.

    In your case I’d say that this particular field should always contain a date right? If so, just an non-empty check should be sufficient right?

    Cheers, Jory

    Thread Starter David Cole

    (@coleds)

    @keraweb I am query the date as the value. The meta_value is “2021-05-31” its saved as a string. I am doing a search in the postmeta for it to print out the post_title/name onto a calendar. As you can see here:

    https://dev.svilleschools.com/events/

    I am creating the calendar, then printing the $pods->total which equals zero. I am looping through each day to find info to echo. I have memorial day and a few other dates saved but nothing is being found.

    Please advise.

    Also if I try to use ‘orderby’ => ‘t.post_title ASC’ it continues it with:

    ORDER BY t.post_title ASC, t.menu_order, t.post_title, t.post_date

    Very strange.

    Thread Starter David Cole

    (@coleds)

    I accomplished this using wpdb get_results with a simple query string…

    If you can explain the below in Pods, it would be much appreciated. The docs are not very helpful.

    $results = $wpdb->get_results("SELECT m.post_id,m.meta_value,p.post_title FROM ".$wpdb->postmeta." AS m LEFT JOIN ".$wpdb->posts." AS p ON m.post_id=p.ID WHERE m.meta_value='".$date."'");

    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @coleds

    Also if I try to use ‘orderby’ => ‘t.post_title ASC’ it continues it with:

    ORDER BY t.post_title ASC, t.menu_order, t.post_title, t.post_date

    These are default sorting additions.

    If you can explain the below in Pods, it would be much appreciated. The docs are not very helpful.

    Since you manually create your own query you don’t need anything Pod related. You just need to query the meta_value in relation to the meta_key.
    When you use the .meta_value value postfix in combination with Pods then it will automatically add all required JOINS etc. to the query to make it work.

    So, if you just want a single date (without time) then your initial post is almost correct. I believe you need to remove the first % wildcard in your LIKE query since date fields always start with the year, nothing else.

    Cheers, Jory

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Initializing and searching returns nothing when data exists.’ is closed to new replies.