<?php
/**
* Posts
*/
class Post {
/**
* Construct
*/
public function __construct() {
add_action( 'pre_get_posts', array( $this, 'post_type_query' ) );
}
/**
* Post type query
*/
public function post_type_query( $query ) {
if ( is_admin() ) {
return;
}
if ( $query->is_search() ) {
return;
}
// Check for post type queries.
if (
'some_post_type' !== $query->get( 'post_type' )
&&
'some_other_post_type' !== $query->get( 'post_type' )
) {
return;
}
// Ignore the singular page.
if ( $query->is_singular ) {
return;
}
$meta_query = $query->get( 'meta_query', array() );
$meta_query = is_array( $meta_query ) ? $meta_query : array();
$meta_query['relation'] = 'OR';
$meta_query[] = array(
'key' => 'prefix_post_status',
'compare' => '!=',
'value' => 'unavailable',
);
$meta_query[] = array(
'key' => 'prefix_post_status',
'compare' => 'NOT EXISTS',
);
$query->set( 'meta_query', $meta_query );
}
}