Ich möchte im Archiv alle Posts mit post_status-> publish und jene mit post_status-> pending des bestimmten Benutzers abrufen.
Dort bin ich jetzt:
$custom_query_args = array( array( 'post_status' =>'pending', 'author' => 2), array( 'post_status' =>'publish', 'author' => 'any'), 'relation' => 'OR' , 'paged' => get_query_var( 'paged' ) ); $custom_query = new WP_Query( $custom_query_args );
Irgendeine Hilfe?
Ihre Einrichtung wird von WP_Query
nicht unterstützt.
Ein Ansatz besteht darin, den posts_where
Filter von WP_Query
( es gibt andere Möglichkeiten, z. B. das Sammeln von Post-IDs aus verschiedenen Abfragen. ), Um die SQL-Abfrage anzupassen.
Um das Ersetzen von Strings zu vermeiden, könnten wir zum Beispiel verwenden:
$custom_query_args = [ 'post_type' => 'post', 'post_status' => 'publish', ]; // Add filter add_filter( 'posts_where', 'wpse_where' ); // Query $custom_query = new WP_Query( $custom_query_args ); // Remove filter remove_filter( 'posts_where', 'wpse_where' );
wo unser benutzerdefinierter Filter-Callback ist:
function wpse_where( $where ) { global $wpdb; return $where . " OR ( {wpdb->posts}.post_author = 2 AND {wpdb->posts}.post_status = 'publish' AND {wpdb->posts}.post_type = 'post' ) "; }
Hoffentlich können Sie dies Ihren Bedürfnissen anpassen.