On this mission, there are customized posts with quite a lot of titles. In every submit with the title that’s the title of an individual (first title, final title), there’s a customized area (custom_title) that may maintain an alternate title (final title, first title).
With a purpose to show the names in a helpful means within the customized archive web page, the item is to test for a price within the custom_title area and if current replace the submit title with the customized title. After the entire relevant titles have been up to date, the question should kind the entire posts by title, all of the whereas recognizing the up to date titles.
Utilizing the code under, the unique titles of the title articles are up to date with the customized titles, however the kind order would not change–it nonetheless types by the unique title.
Thanks for taking the time to assist!
operate cchs_swap_title( $updatedTitle)
{
$customTitle = get_post_meta( get_the_ID(), 'custom_title', true);
if(!empty($customTitle))
{
$updatedTitle = $customTitle;
}
return $updatedTitle;
}
add_filter( 'the_title', 'cchs_swap_title');
operate cchs_archives_orderby( $the_query ) {
if(!is_admin() && $the_query->is_main_query())
{
$the_query->set( 'orderby', 'title' );
$the_query->set( 'order', 'DESC' );
}
}
add_action( 'pre_get_posts', 'cchs_archives_orderby', 99999 );
$args = array(
'post_type' => 'cchs_article',
'posts_per_page' => -1
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) :
whereas ( $the_query->have_posts() ) : $the_query->the_post();
get_template_part( 'template-parts/content material', 'archive-cchs_article');
endwhile;
wp_reset_postdata();
else :
get_template_part( 'template-parts/content material', 'none' );
endif;