Jump to content

Find values by field name


Matzn
 Share

Recommended Posts

Yea, my first post. I used processwire a time, but always all questions a found in this great forum. Thanks to all members.

I know, i finding a page by selector. Like this:

$pages->find('template=repeater_products, check_access=0, product_keyword=' . $page->title);

But, how i find all values by a field name? For example, the code below give 3 results, now i want all values from a field as array. E.g. product_option_key from my screenshot like this:

[0] => Speicher
[1] => Farbe

 

At time i use the php way, like this:

$productOverviewList = $pages->find('template=repeater_products, check_access=0, product_keyword=' . $page->title);

$productOptionList = [];
foreach ($productOverviewList as $item) {
    foreach ($item->product_options as $key) {
        if (array_key_exists($key->product_option_key->title, $productOptionList)) {
            $str = $productOptionList[$key->product_option_key->title] . ",";
            $str .= $key->product_option_value;
            $productOptionList[$key->product_option_key->title] = $str;
        } else {
            $productOptionList[$key->product_option_key->title] = $key->product_option_value;
        }
    }
}

Maybe you have a better solution for me?

Screenshot 2020-09-25 165857.jpg

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...