Skip to content

Instantly share code, notes, and snippets.

@kjtolsma
Last active April 22, 2022 20:56
Show Gist options
  • Save kjtolsma/dd0ee8d3cb60006349509ef2774b894a to your computer and use it in GitHub Desktop.
Save kjtolsma/dd0ee8d3cb60006349509ef2774b894a to your computer and use it in GitHub Desktop.
$page_id = get_the_ID();
/* Tax query */
$tax_query = array();
if ( true ) {
$tax_query[] = array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'general',
);
}
/* Meta query */
$meta_query = array();
if ( true ) {
$meta_query[] = array(
'key' => '_wp_page_template',
'value' => 'page-templates/compact.php',
'compare' => '='
);
}
$query = new WP_Query( array(
'post_type' => 'page',
'posts_per_page' => 10,
'meta_query' => $meta_query,
'tax_query' => $tax_query,
'no_found_rows' => true,
'suppress_filters' => false,
) );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
// Don't show duplicate post
if ( get_the_ID() === $page_id ) {
continue;
}
// Don't show this post.
if ( true ) {
continue;
}
the_title();
}
wp_reset_postdata();
}
/**
* Pre get posts for all loops
*/
add_filter( 'pre_get_posts', array( $this, 'archive_query' ) );
public function archive_query( $query ) {
if ( is_admin() ) {
return;
}
if ( 'vacancy' !== $query->get( 'post_type' ) ) {
return;
}
$meta_query = $query->get( 'meta_query', array() );
$meta_query = is_array( $meta_query ) ? $meta_query : array();
$meta_query[] = array(
'key' => 'wender_vacancy_end_date',
'value' => gmdate( 'Ymd' ),
'compare' => '>=',
);
$query->set( 'meta_query', $meta_query );
}
/**
* Pre get posts for archives
*/
add_filter( 'pre_get_posts', array( $this, 'archive_query' ) );
public function archive_query( $query ) {
if ( is_admin() ) {
return;
}
if ( ! $query->is_main_query() ) {
return;
}
if ( ! $query->is_post_type_archive( 'experience' ) ) {
return;
}
$experience_category = filter_input( INPUT_GET, 'experience_category', FILTER_SANITIZE_STRING );
$tax_query = $query->get( 'tax_query', array() );
$tax_query = is_array( $tax_query ) ? $tax_query : array();
if ( $experience_category ) {
$tax_query[] = array(
'taxonomy' => 'experience_category',
'field' => 'slug',
'terms' => $experience_category,
);
}
$query->set( 'posts_per_page', 36 );
$query->set( 'tax_query', $tax_query );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment