post meta - get_post_meta not work in PHP foreach

admin2025-01-07  3

I have these codes :

require_once( dirname(__DIR__) . '/wp-load.php');

foreach ( $ids as $idss ) {
    echo  get_post_meta($idss, 'IMDB', true);
}

I have search box with form element that search and find all id ( $ids ) of searched word.

I want to print all $ids's IMDB field. I can do it on page.php of the Theme, but I can't do it on header.php.

I used global $post; and it did not work.

I have these codes :

require_once( dirname(__DIR__) . '/wp-load.php');

foreach ( $ids as $idss ) {
    echo  get_post_meta($idss, 'IMDB', true);
}

I have search box with form element that search and find all id ( $ids ) of searched word.

I want to print all $ids's IMDB field. I can do it on page.php of the Theme, but I can't do it on header.php.

I used global $post; and it did not work.

Share Improve this question edited Jul 31, 2024 at 13:26 bueltge 17.1k7 gold badges61 silver badges97 bronze badges asked Nov 2, 2016 at 0:40 Hamed ApHamed Ap 112 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Is your $ids array empty? Echo out each $idss to see if it contains a value.

foreach ( $ids as $idss ) {
  echo $idss . ' <-- ID<br>';
  echo  get_post_meta( $idss, 'IMDB', true );
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736254112a178.html

最新回复(0)