WordPress.org

Ready to get started?Download WordPress

Forums

Simple Fields
[resolved] Accessing simple-fields in get_posts loop (5 posts)

  1. jklina
    Member
    Posted 1 year ago #

    I can access the simple-fields values via:

    %p.event-description= simple_fields_value('test')

    in the main have_posts() loop, however when I'm using:

    - $recent_events = get_posts(...)

    The simple_fields_value('test') does not retrieve my simple fields value. Any ideas how to get this to work in my secondary loop?

    Thanks for looking!

    http://wordpress.org/extend/plugins/simple-fields/

  2. Pär Thernström
    Member
    Plugin Author

    Posted 1 year ago #

    Depending on the way you loop, this is one solution:

    foreach ($recent_events as $one_event) {
    
      $value = simple_fields_value('test', $one_event->ID);
    
    }
  3. jklina
    Member
    Posted 1 year ago #

    Ah, thank you. Specifying the ID explicitly helps.

  4. Pär Thernström
    Member
    Plugin Author

    Posted 1 year ago #

    Yes, but as I said, it all depends on how you do the loop. If you did the loop using wp_query() then you would not have to use the id explicitly. Then your first try would work, something like:

    $custom_query = new wp_query($query_args);
    while($custom_query->have_posts()) : $custom_query->the_post();
        $value = simple_fields_value('test');
    endwhile;
    wp_reset_postdata();
  5. jklina
    Member
    Posted 1 year ago #

    Excellent, thanks for the explanation. I'm new to WP so I'm still learning the nuances of defining multiple loops and such. A new instance of WP_Query seems reasonable.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic