Support

Home Forums Event Espresso Premium EE4 – Order by Sort By

EE4 – Order by Sort By

Posted: September 13, 2017 at 9:43 am


JacquesMivi

September 13, 2017 at 9:43 am

Hello,

How can I sort “EEM_Registration::instance()->get_all” with a spicific list , like that ?


	$registrations = EEM_Registration::instance()->get_all(
		array(
			array(
				'Event.EVT_wp_user' => $USR_ID,
				'STS_ID'            => array(
					'IN',
					array(
						'RAP',
						'RNA',
						'RDC',
						'RCN',
					)
				)
			),
			'order_by' => 'STS_ID',
			'order'     => array(
				'RAP',
				'RNA',
				'RDC',
				'RCN',
			)
		) );

Thanks a lot for your help,


Tony

  • Support Staff

September 13, 2017 at 11:42 am

Hi there,

Currently, you can’t do that with the models, you can only set a field to order by and ASC or DESC.

I’ve created a feature request ticket to see if this is something we can add into our models but in the meantime, you would need to run the query yourself using $wpdb.

For example, if you use the models to generate a without the order or order_by set, then output the query, you’ll get something like this:

SELECT Registration.REG_ID AS 'Registration.REG_ID', Registration.EVT_ID AS 'Registration.EVT_ID', Registration.ATT_ID AS 'Registration.ATT_ID', Registration.TXN_ID AS 'Registration.TXN_ID', Registration.TKT_ID AS 'Registration.TKT_ID', Registration.STS_ID AS 'Registration.STS_ID', Registration.REG_date AS 'Registration.REG_date', Registration.REG_final_price AS 'Registration.REG_final_price', Registration.REG_paid AS 'Registration.REG_paid', Registration.REG_session AS 'Registration.REG_session', Registration.REG_code AS 'Registration.REG_code', Registration.REG_url_link AS 'Registration.REG_url_link', Registration.REG_count AS 'Registration.REG_count', Registration.REG_group_size AS 'Registration.REG_group_size', Registration.REG_att_is_going AS 'Registration.REG_att_is_going', Registration.REG_deleted AS 'Registration.REG_deleted' FROM wp_esp_registration AS Registration WHERE Registration.REG_deleted = 0 AND Registration.STS_ID IN ('RAP','RNA','RDC','RCN');

Add something like ORDER BY FIND_IN_SET(Registration.STS_ID,'RAP,RNA,RDC,RCN');
to the query and manually run it on your database using $wpdb and you have your results.

Note the above is unsupported and should be considered untested, it’s just something I put together whilst investigating your question.

The support post ‘EE4 – Order by Sort By’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso