wp query id code example
Example 1: wp query
<?php
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
} else {
}
wp_reset_postdata();
Example 2: wp query search
$query = new WP_Query( array( 's' => 'keyword' ) );
Example 3: wp query get ids
function carawebs_student_questionnaire_results(){
$args = array(
'post_type' => 'questionnaire-result',
'post_status' => 'publish',
'fields' => 'ids',
'meta_query' => array(
array(
'key' => 'user_type',
'value' => 'student',
'compare' => '=',
'type' => 'CHAR',
),
),
);
$result_query = new WP_Query( $args );
$ID_array = $result_query->posts;
wp_reset_postdata();
return $ID_array;
}