0

How can I display records that were created on the current date using views. I have used the now value on the created date filter but the records are not showing. I think its because now also includes the the current time. Please Help?

0

You can use Content: Authored on in views filter criteria and specify offset today. I was able to achieve event date filter using below code. I was able to achieve this using custom coding may be it will help you.

function common_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
if ($view->id() == 'new_page' && $view->getDisplay()->display['id'] == 'news_present_year') {
       // print_r($query->where[1]['conditions'][2]);
        $current_yr_start = strtotime(date('Y-01-01'));
        $current_yr_end = strtotime(date('Y-12-31'));
        $current_yr = 'node_field_data.created BETWEEN ' .$current_yr_start.' AND '.$current_yr_end;
        //$current_yr= 'node_field_data.created = '.strtotime(date('Y-01-01'));
        $query->where[1]['conditions'][2]['field']= $current_yr;

        /*print_r($query->where[1]['conditions'][2]);
       kint($query->where[1][3]);
        dpm($query);*/
        }
        if ($view->id() == 'new_page' && $view->getDisplay()->display['id'] == 'news_block') {
        //print_r($query->where[1]['conditions'][2]);
        $current_yr= 'node_field_data.created < '.strtotime(date('Y-01-01'));
        $query->where[1]['conditions'][2]['field']= $current_yr;

        //print_r($query->where[1]['conditions'][2]);
        }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.