add_action( 'wp', $this, 'suppress_page_title' );
}
/**
* Fired on every frontend request for the projects archive page.
* Sets pyre_page_title (Avada) and adds the_title filter (Gutenberg / any theme).
*/
public function suppress_page_title(): void {
if ( ! is_singular( 'page' ) ) {
return;
}
$archive_id = (int) get_option( 'academiccrew_collaborations_archive_page_id', 0 );
if ( ! $archive_id || get_queried_object_id() !== $archive_id ) {
return;
}
update_post_meta( $archive_id, 'pyre_page_title', 'no' );
add_filter( 'the_title', [ $this, 'blank_archive_title' ], 10, 2 );
}
/** Returns empty string for the archive page title rendered inside the loop. */
public function blank_archive_title( string $title, int $id = 0 ): string {
$archive_id = (int) get_option( 'academiccrew_collaborations_archive_page_id', 0 );
return ( $archive_id && (int) $id === $archive_id && in_the_loop() ) ? '' : esc_html( $title );
}
public function render( array $atts ): string {
$atts = shortcode_atts( [
'per_page' => -1,
], $atts, 'academiccrew_projects' );
$query = new \WP_Query( [
'post_type' => 'acc_collaboration',
'post_status' => 'publish',
'posts_per_page' => (int) $atts['per_page'],
'orderby' => 'title',
'order' => 'ASC',
] );
// Most recent projects first (by start date), then A→Z by title.
$start_of = static fn( \WP_Post $p ): string =>
(string) get_post_meta( $p->ID, '_acc_start_date', true ) ?: '0000-00-00';
usort( $query->posts, static function ( $a, $b ) use ( $start_of ) {
return strcmp( $start_of( $b ), $start_of( $a ) ) ?: strcasecmp( $a->post_title, $b->post_title );
} );
wp_enqueue_script(
'academiccrew-projects-archive',
ACADEMICCREW_URL . 'assets/js/projects-archive.js',
[],
ACADEMICCREW_VERSION,
true
);
$found = $query->found_posts;
// Collect unique keyword labels (original case) for the datalist autocomplete.
$all_keywords = [];
foreach ( $query->posts as $post ) {
$kw_raw = get_post_meta( $post->ID, '_acc_keywords', true );
foreach ( ( is_array( $kw_raw ) ? $kw_raw : [] ) as $kw ) {
$kw = trim( (string) $kw );
if ( $kw !== '' && ! in_array( $kw, $all_keywords, true ) ) {
$all_keywords[] = $kw;
}
}
}
sort( $all_keywords );
ob_start();
?>