Output categories as an array?

  • Hi


    I'm trying to access a category set within a perch_collection, but when I run echo all that's output is the word Array?


    Code
    1. $wlrs_cats = perch_collection('Opportunities', [
    2. 'skip-template' => 'true',
    3. 'return-html' => 'true',
    4. 'filter' => 'opp_name_slug',
    5. 'match' => 'eq',
    6. 'value' => perch_get('s'),
    7. ]);
    8. echo $wlrs_cats[0]['content_type']; // Opportunity categories - outputs 'Array'?
    9. echo $wlrs_cats[0]['opp_name']; // Opportunity name - outputs name as expected.


    How do I output the full Array, I'm expecting to echo a string of all the selected categories.:/

  • Thanks for the reply.


    If I use perch_categories() or perch_category() how do I relate them to the perch_collection?


    Within perch_collection('Opportunities' the admin might select one or all four categories, I'm looking for a way to expose the category paths. I'm hoping I can then convert them into a variable and use them as part of a filter, to filter a different perch_collection

  • If I use perch_categories() or perch_category() how do I relate them to the perch_collection?


    You can use the returned array to filter the categories:


  • Hi


    Thanks for the example, unfortunately I couldn't get it to work - however I was able to use implode(',', $wlrs_cats[0]['content_type']) to get what I was looking for. Thanks!


    This outputs the category paths of the current item filtered by slug:



    So $categories; outputs content-type/listen-up/,content-type/case-studies/


    I wanted to use the category path to allow the admin to choose what categories to show in another collection.


    So I used this to convert the category paths into a variable I could use in another template



    This takes the category paths


    content-type/listen-up/,content-type/case-studies/


    and leaves me with just the category name, which I then uppercase and remove the hyphen. This then matches the the name of an ID in another template which then lets me use perch:if


    <perch:if id="wlrs_cats_edit" match="contains" value="{collectionKey}">...</perch:if>


    Thanks for your help hus_hmd :)