I had had the following code in my php template file.
<?php
$childargs = array(
'post_type' => 'attorney',
'numberposts' => -1,
'meta_key' => 'wpcf-last-name',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_query' => array(array(
'key' => '_wpcf_belongs_locations_id',
'value' => get_the_ID()))
);
$child_posts = get_posts($childargs);
foreach ($child_posts as $child_post) {
if(get_post_meta($child_post->ID, 'wpcf-office-contact', true) == '1') :
echo '
';
echo $child_post->post_title;
if( get_post_meta($child_post->ID, 'wpcf-title') ):
echo ' (' . get_post_meta($child_post->ID, 'wpcf-title', true) . ')';
//echo ''.'
';
endif;
echo '';
endif;
}
?>
<?php
$childargs = array(
'post_type' => 'attorney',
'numberposts' => -1,
'meta_key' => 'wpcf-last-name',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_query' => array(array(
'key' => '_wpcf_belongs_locations_id',
'value' => get_the_ID()))
);
$child_posts = get_posts($childargs);
foreach ($child_posts as $child_post) {
echo '
';
echo $child_post->post_title;
if( get_post_meta($child_post->ID, 'wpcf-special-note') ):
echo ' (' . get_post_meta($child_post->ID, 'wpcf-special-note', true) . ')';
//echo ''.'
';
endif;
echo '';
}
?>
Before migration to new post relationships, the pages looked like the attached ("Before Migration.png")
After migration the page looks like the attached ("After Migration.png")
I tried changing the code to this (below) (like i saw on this page https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/ ), but after doing so, only a partial list displayed.
<?php
$query = new WP_Query(
array(
'post_type' => 'attorney',
'numberposts' => -1,
//new toolset_relationships query argument
'toolset_relationships' => array(
'role' => 'child',
'related_to' => get_the_ID(),
// this will work only with relationships that have existed before the migration
// if possible, use the relationship slug instead of an array
'relationship' => array( 'locations', 'attorney' )
),
'meta_key' => 'wpcf-last-name',
'orderby' => 'meta_value',
'order' => 'ASC',
)
);
$posts = $query->posts;
foreach ($posts as $child_post) {
echo '
';
echo $child_post->post_title;
if( get_post_meta($child_post->ID, 'wpcf-special-note') ):
echo ' (' . get_post_meta($child_post->ID, 'wpcf-special-note', true) . ')';
//echo ''.'
';
endif;
echo '';
}
?>
Can you let me know what wrong and how I can fix it?