I have a php comparison which is working.
if ( $query->get('post_type') == 'motogp-2014')
But I need to check multiple post types and I was wondering if there is a short way or keeping this all in one line.
I've tried this...
$motogp_seasons = array('motogp-2013','motogp-2014');
if ( $query->get('post_type') == $motogp_seasons )
and this...
$motogp_seasons = array('motogp-2013','motogp-2014');
if ( in_array( $query->get('post_type'), $motogp_seasons ) )
But none seem to work.
Can any help with another php solution please.
Many thanks
you can use foreach
for traverse your array and then compare it like this
$motogp_seasons = array('motogp-2013','motogp-2014');
foreach($motogp_seasons as $motogp_seasons_val)
{
if ($query->get('post_type') == $motogp_seasons_val)
{
echo $motogp_seasons_val." is equal <br/>";
}
else
{
echo $motogp_seasons_val." is not equal <br/>";
}
}
Try making your variable global...
global $motogp_seasons
$motogp_seasons = array('motogp-2013','motogp-2014');
function order_events_by_date($query) {
global $motogp_seasons;
if ( in_array( $query->get('post_type'), $motogp_seasons ) ) {
// Stuff here
}
}