Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACF Options page #48

Open
omzy opened this issue Aug 7, 2017 · 8 comments
Open

ACF Options page #48

omzy opened this issue Aug 7, 2017 · 8 comments

Comments

@omzy
Copy link
Contributor

omzy commented Aug 7, 2017

How do we retrieve values from an Options page?

https://www.advancedcustomfields.com/resources/options-page/

I added a gallery field within an options page, when I do Option::get('gallery') it outputs an array (which is correct), however that array only contains key => value pairs, like this:

image

How do I get the actual images?

@jgrossi
Copy link
Member

jgrossi commented Aug 7, 2017

@omzy83 no no, for ACF stuff only use $post->acf->gallery('field') not Option::get(). You should receive a collection of images ;-)

@omzy
Copy link
Contributor Author

omzy commented Aug 7, 2017

@jgrossi I think you misunderstood...

I created the gallery in the Options page because it will be used on different pages on the site. I.e the same gallery with the same images reused across different pages.

@jgrossi
Copy link
Member

jgrossi commented Aug 7, 2017

@omzy83 hum good call, I don't think we already have get_option() covered... it's easy to implement but I think it's not working yet...

@omzy
Copy link
Contributor Author

omzy commented Aug 7, 2017

As a workaround for now, I have done this which seems to work:

<?php

namespace App\Models;

use App\Models\Post;

class Option extends \Corcel\Model\Option
{
    public static function getGallery()
    {
        // 'options_gallery' is the name of my Options page field
        $gallery_option = self::get('options_gallery');

        $gallery = [];

        foreach ($gallery_option as $index => $id) {
            $post = Post::find($id);
            $image = $post->url;

            $gallery[] = $image;
        }

        return $gallery;
    }
}

@jgrossi
Copy link
Member

jgrossi commented Aug 30, 2017

@omzy83 cool, but maybe we can think in a general method to handle this.

@OwenMelbz
Copy link

@jgrossi hey has this moved forwards at all? would really like to use this in a active project!

@jgrossi
Copy link
Member

jgrossi commented Feb 9, 2018

@OwenMelbz not actually, maybe someone can create a PR for that?

@tbruckmaier
Copy link

I am currently working on a pr for this, unfortunately it requires a bunch of changes. The more complex fields like repeater or even image need to retrieve additional data from wp_posts and wp_postmeta. The logic for this is currently in the single field classes. The acf option page stores its data in wp_options though, that's why its not working with the current approach.
My approach is to move the logic for additional fields to a new layer (called "repository" now in lack of a better name), so we have a PostRepository (with the current logic from the single Field classes) and a new OptionPageRepository. The single fields do interact with the database only through their repository, so we should be fine there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants