Aquí está la situación, tengo un impuesto personalizado llamado Skill . Quiero poder mostrar publicaciones solo con el conjunto de habilidades como japonés desde inglés.
Estoy tratando de aprender a usar el gancho pre_get_posts para modificar mi consulta get_posts . Aquí está mi ejemplo, sin embargo, aterrizo con el error:
Aviso: Variable indefinida: postdata
Esto es lo que he intentado basado en la investigación:
add_filter( 'pre_get_posts', 'wpshout_fundraiser_recent_posts' ); function wpshout_fundraiser_recent_posts( $query ) { // Fetch only posts tagged with "Japanese from English" $taxquery = array( array( 'taxonomy' => 'Japanese from English', 'field' => 'skill', 'terms' => array( 'skill' ), ) ); $query->set( 'tax_query', $taxquery );Estoy seguro de que algo está mal con la consulta anterior, que no entiendo completamente. Cualquier ayuda y, si es posible, explique para qué sirve cada campo de la matriz.
Pruebe este código a continuación, esto debería funcionar,
add_filter( 'pre_get_posts', 'wpshout_fundraiser_recent_posts' ); function wpshout_fundraiser_recent_posts( $query ) { $posts_array = get_posts( array( 'posts_per_page' => -1, 'post_type' => 'Your Post Type Name', 'tax_query' => array( array( 'taxonomy' => 'Japanese from English', 'field' => 'skill', 'terms' => array( 'skill' ), ) ) ) ); return $posts_array; }Aquí puedes consultar:
$args = array( 'posts_per_page' => 5, 'post_type' => 'Post Type Name', 'tax_query' => array( array( 'taxonomy' => 'category_taxonomy', 'field' => 'slug', 'terms' => "Category Name" ))); $query = query_posts( $args ); while (have_posts()) : the_post(); the_content(); endwhile;$posts_array = get_posts( array( 'posts_per_page' => -1, 'post_type' => 'post_type_name', 'tax_query' => array( array( 'taxonomy' => 'taxonomy-name', 'field' => 'term_id', 'terms' => $cat->term_id, ) ) ) );