TLDR: My custom post type items are sorting differently on a local environment and a live server. Can’t figure out why!
I have a local install (MAMP) and an online dev install (GoDaddy shared, for the client to view) of a site with pages of Custom Post Type posts. The CPT posts are real estate properties. The CPT posts have meta info added using Advanced Custom Fields. The ACF fields include the state each property is in and the type of property.
Here is a relevant page CPT page for Wisconsin posts
The CPT posts are divided into three pages by state. Within each state page, the properties are sorted by type of property. That is it – they are sorted into their states and then sorted by type of property.
I used a WP_query to do this for each page. Here is the query for the Wisconsin page:
$args=array(
'post_type' => 'properties',
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_query' => array(
'state_clause' => array('key' => 'state', 'value' => 'WI'),
'prop_type' => array('key' => 'property_type'),
),
'orderby' => array(
'prop_type' => 'ASC'
)
);
$wiQuery = new WP_Query($args);
?>
<?php
if( $wiQuery->have_posts() ) {
while ($wiQuery->have_posts()) : $wiQuery->the_post();
The sort is working fine for the state pages. In other words, all the Wisconsin properties appear on the right page, and they are grouped property in order of the ACF meta field for Property Type.
However, within those groups the properties appear in a different order on the local MAMP site than they do on the dev install. For example, on the local install, 1501 Paramount Drive appears before 1209 Deming Way. Which seems really odd to me!
The dev site and the local site are both the same version of WordPress and the exact same custom theme I’m working on. They are using the same version of ACF. 95% of the posts were added to the local site before it was uploaded to the dev location.
Could it be differences with PHP versions (seems unlikely) or something about the mysql version?
The Properties custom post type itself has a weird origin. A developer set it up many years ago using the Easy Custom Post Type plugin, which no longer works. I deactivated that plugin and added the CPT to the functions file and I was able to use all the properties that were added with ECPT. I just had to redo all the meta data.
This is not an urgent issue, it’s just baffling. If anyone has any ideas of why the sort would be different on different servers I’d be grateful to hear them.