Random Polls not showing
-
Hi! I have created two polls and set the Yop widget (displaying in the sidebar) to display random polls. However, for some reason, only the first Poll is shown and the second Poll is just a blank (when changing page/post). When I change the widget to just show the Poll that, previously, was blank, it displays as it should. Treble checked all settings and can’t figure out why random is nor working. Possible bug? Any help would be appreciated.
-
Hi thpword,
Please let us know what YOP Poll version you use so we may assist.
Regards,
YOP Team
Thanks for getting back. Version 5.1
Just did another check and also not showing for latest Poll i.e. if more than 1 Poll, Poll 2 onwards are not showing at all.
Hey,
Edit abstract_model.php and in __construct function, right above this line
$data = self::get_data_by( 'id', $id );addif($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
Hi,
I did as you said but there is still blank in my yop widget. Only first poll is displayed.
Awaiting for fixes.
Regards,
ElvinHello
Please send us a link so we can look into this further.
Best
YOP TeamHi,
this happens because of the wrong ID, if you have deleted a poll before.
Perhaps you shouldn´t get the poll item by rand over all items.i have changed the code in abstract_model.php (line: 131+) from:
if( count($total_polls)>1) { while($ok==0){ $id=rand ( 1 , count($total_polls)); $poll=new YOP_POLL_Poll_Model($id); if( $current_date <= convert_date( $poll->poll_end_date, 'Y-m-d H:i:s' ) ) { $ok=1; } } }to this:
if(count($total_polls)>1) { while($ok==0){ $randomPollId = array_rand ($total_polls); $id = $total_polls[$randomPollId]['ID']; $poll=new YOP_POLL_Poll_Model($id); if( $current_date <= convert_date( $poll->poll_end_date, 'Y-m-d H:i:s' ) ) { $ok=1; } } }Thanks a lot, Schubie!
That solved the problem for me.
Combination of the above code edits, appears to have fixed the issue. Many thanks.
The topic ‘Random Polls not showing’ is closed to new replies.