I ran a PHP query for my WordPress site with the following code:
$args = array(
'post_type' => 'cases',
'posts_per_page' => 3,
offset => 2
);
$the_query1 = new WP_Query( $args );
if ( $the_query1 -> have_posts() ):
print_r($the_query1);
while ( $the_query1->have_posts() ): $the_query1->the_post();
This is the object returned:
WP_Query Object
(
[query] => Array
(
[post_type] => cases
[posts_per_page] => 3
[offset] => 2
)
[query_vars] => Array
(
[post_type] => cases
[posts_per_page] => 3
[offset] => 2
[paged] => 0
[embed] =>
[category__in] => Array
(
)
[update_post_term_cache] => 1
[lazy_load_term_meta] => 1
[update_post_meta_cache] => 1
[nopaging] =>
[comments_per_page] => 50
[no_found_rows] =>
[order] => DESC
)
[tax_query] => WP_Tax_Query Object
(
[queries] => Array
(
)
[relation] => AND
[primary_table] => wp_posts
[primary_id_column] => ID
)
[request] => SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'cases' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'acf-disabled' OR wp_posts.post_status = 'private') ORDER BY wp_posts.post_date DESC LIMIT 2, 3
[posts] => Array
(
[0] => WP_Post Object
(
[ID] => 19163
[post_author] => 2
[post_date] => 2018-09-28 15:42:12
[post_content] =>
[post_title] => Global Factories
[post_modified] => 2018-11-15 12:41:57
[post_modified_gmt] => 2018-11-15 11:41:57
[post_content_filtered] =>
[post_parent] => 0
[guid] => https://www.zeo.nl/?post_type=cases&p=19163
[menu_order] => 0
[post_type] => cases
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
[1] => WP_Post Object
(
[ID] => 19167
[post_author] => 2
[post_date] => 2018-09-21 14:58:50
[post_content] =>
[post_title] => Warmteservice Groep B.V.
[post_modified] => 2018-11-15 12:00:56
[post_modified_gmt] => 2018-11-15 11:00:56
[post_content_filtered] =>
[post_parent] => 0
[guid] => https://www.zeo.nl/?post_type=cases&p=19167
[menu_order] => 0
[post_type] => cases
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
[2] => WP_Post Object
(
[ID] => 19157
[post_author] => 2
[post_date] => 2018-09-21 11:26:12
[post_content_filtered] =>
[post_parent] => 0
[guid] => https://www.zeo.nl/?post_type=cases&p=19157
[menu_order] => 0
[post_type] => cases
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
)
[post_count] => 3
[current_comment] => -1
[found_posts] => 43
[max_num_pages] => 15
[max_num_comment_pages] => 0
[query_vars_hash:WP_Query:private] => 63c13903269b2ec070d244b97926b6e4
[query_vars_changed:WP_Query:private] =>
[thumbnails_cached] =>
[stopwords:WP_Query:private] =>
[compat_fields:WP_Query:private] => Array
(
[0] => query_vars_hash
[1] => query_vars_changed
)
)
If you look in the middle of the object, there is an object property called [posts] which is an array consisting of three properties. I would like to access this property and then check if the second index ([1]) is true and do something based on that. Unfortunately, I am not sure how to access that property in PHP. Please advise.