0

I would like to ask if there's a way on WordPress to get fetch all of the page's Field?... I am using a Advance Custom Field Plugin and would like to fetch data's from fields inputted over those fields from different pages..

So i have found a way to this already using this:

        <?php 
    for ($x = 0; $x <= 1000; $x++) {
    $rows = get_field('about_hotel', $x);
    if($rows)
      {
        echo '<ul>';

        foreach($rows as $row)
        {
          echo '<h1> ' . $row['hotel_name'] . '</h1><br/>'.'<p>' . $row['hotel_description'] . '</p>';
        }
        echo '</ul>';

      }}
    ?>

But This way is quite unorthodox or is a very bad habit to use... can someone help me with this?

It would be very much appreciated.. Thank You...

5
  • Did you try get_pages() ?
    – Sumit
    Commented May 9, 2016 at 16:41
  • Hello @jan-jvos. If you want to get all fields of a post, you can try get_post_custom(). If you want to get all fields of a post from ACF plugin, ask to the developer of ACF plugin how to do it. Questions about third party plugins are off-topic here.
    – cybmeta
    Commented May 9, 2016 at 17:02
  • @Sumit i haven't tried that function yet... can you show me a way to use that function?
    – Jan JVOS
    Commented May 9, 2016 at 17:17
  • @cybmeta ohhh.. okay it isn't allowed to ask about third party plugin in here... but was just hoping someone could... been bugged by this problem for almost 4hrs... how do we relay that get_post_custom function? i haven't heard of it yet... just a newbee who just got deeper on wordpress..
    – Jan JVOS
    Commented May 9, 2016 at 17:18
  • I've read your question again and I don't understand what you are asking. "fetch all of the page's Field" suggests one thing, "request all post ID in a loop" suggests another thing. Can you please edit your question and explain what exactly are you asking?
    – cybmeta
    Commented May 9, 2016 at 19:25

1 Answer 1

0

Currently from your code I can see you are looping for post IDs from 1 to 1000 that isn't good. WordPress have lot of functions by which you can fetch post IDs, content and other information. One of them (according to your need) is get_pages()

Check the documentation of get_pages() there are lot of examples.

See the Example from above code:-

$all_pages = get_pages(array(
    'number' => -1
));

foreach ($all_pages as $page) {
    $rows = get_field('about_hotel', $page->ID);
    if($rows) {
        echo '<ul>';

        foreach($rows as $row)
        {
          echo '<h1> ' . $row['hotel_name'] . '</h1><br/>'.'<p>' . $row['hotel_description'] . '</p>';
        }
        echo '</ul>';

      }    
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.