get_posts shows current post, not defined posts with args
-
I want to show defined posts but get_posts shows current post without use definition in args.Why, how to solve it? what is difference between get_posts and wp query? thanks
——————————–
an user on stackoverflow shared this “solution” but it is so fast answer and I couldn’t work it:
global $post; // This... foreach ($post_types1 as $post_type1) { $post = $post_type1; // ...and this. setup_postdata( $post_type1 ); // etc. } wp_reset_postdata();
——————————-
add_action( 'template_redirect', 'check_shop' ); function check_shop() { if (is_shop() ) { $args1 = array( 'post_author' => 'admin', 'post_type' => 'page', ); $post_types1 = get_posts( $args1, 'objects' ); foreach ($post_types1 as $post_type1) { setup_postdata( $post_type1 ); if (!empty($post_type1->post_content)) { add_action('woocommerce_before_shop_loop_item_title', function() { global $post_type1; the_title(); echo get_the_title($post_type1->ID); echo $post_type1; echo $post_type1->post_content; echo "denemeee yaz?s?"; }, 1); } } wp_reset_postdata(); } }
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘get_posts shows current post, not defined posts with args’ is closed to new replies.