Hey,
Edit abstract_model.php and in __construct function, right above this line
$data = self::get_data_by( 'id', $id );
add
if($id=="-3"){
$filters = array();
$filters[] = array(
'field' => 'poll_type',
'value' => 'poll',
'operator' => '='
);
$filters[] = array(
'field' => 'poll_start_date',
'value' => current_time( 'mysql' ),
'operator' => '<='
);
$args = array(
'return_fields' => 'ID ',
'filters' => $filters,
'search' => array(
),
'orderby' => "poll_start_date",
'order' => 'DESC'
);
$total_polls = Yop_Poll_Model::get_polls_filter_search( $args );
$id=rand ( 1 , count($total_polls));
}
Next, edit yop_poll_model.php and make sure it contains this function:
public static function get_polls_filter_search( $args ) {
$return_fields = '*';
$filters = null;
$search = null;
$orderby = 'ID';
$order = 'ASC';
$limit = null;
if( isset( $args['return_fields'] ) ) {
$return_fields = trim( $args['return_fields'], ',' );
}
if( isset( $argsz['filters'] ) ) {
$filters = $args['filters'];
}
if( isset( $args['search'] ) ) {
$search = $args['search'];
}
if( isset( $args['orderby'] ) ) {
$orderby = $args['orderby'];
}
if( isset( $args['order'] ) ) {
if( in_array( strtoupper( $args['order'] ), array( 'ASC', 'DESC' ) ) ) {
$order = $args['order'];
}
}
if( isset( $args['limit'] ) ) {
$limit = $args['limit'];
}
$sql = 'SELECT ' . $return_fields . ' FROM ' . $GLOBALS['wpdb']->yop_polls . ' WHERE 1=1 ';
$sql_filter = '';
if( count( $filters ) > 0 ) {
foreach( $filters as $filter ) {
$sql_filter .= ' AND ' . $GLOBALS['wpdb']->prepare( ' <code>' . esc_attr( $filter['field'] ) . '</code> ' . $filter['operator'] . ' %s ', esc_attr( $filter['value'] ) ) . ' ';
}
}
$sql_search = '';
if( count( $search['fields'] ) > 0 ) {
foreach( $search['fields'] as $field ) {
$sql_search .= $GLOBALS['wpdb']->prepare( ' <code>' . esc_attr( $field ) . '</code> like \'%%%s%%\' OR', $search['value'] );
}
$sql_search = ' AND ( ' . trim( $sql_search, 'OR' ) . ' ) ';
}
$sql_order_by = ' ORDER BY ' . esc_attr( $orderby ) . ' ' . esc_attr( $order ) . ' ';
$sql_limit = '';
if( $limit ) {
$sql_limit = ' LIMIT ' . $limit . ' ';
}
return $GLOBALS['wpdb']->get_results( $sql . $sql_filter . $sql_search . $sql_order_by . $sql_limit, ARRAY_A );
}
If it’s not there, please add it.
Regards,
YOP Team