Hot answers tagged get-posts
Random ordering is quite expensive operations in SQL and can become a headache on very big sites. Getting a random post from a category for 6 categories will mean you might need to run 6 separate queries, each ordered randomly. This can really break the bank and leave you bankrupt. From your answer and looking at the fact that you said you are running 30 ...
I just fix it using bueltge sugestion such us: foreach ( $cat_id_array as $cat ) : $args = array( 'posts_per_page' => 1, 'cat' => $cat ); $myposts = get_posts( $args ); //var_dump($myposts); foreach($myposts as $posts) : var_dump($posts->ID); endforeach; endforeach; which is working fine now. Thanks for the heads ...
It is because you're using a reserved term "year". https://codex.wordpress.org/Reserved_Terms
Only top voted, non community-wiki answers of a minimum length are eligible