Store pages in array if "condition"
-
Hello everyone,
I’m converting a static HTML website to a WordPress theme and things were going pretty well until now..
I have already searched the forum and Google but I can’t find the answer to my problem.I have 5 categories of pages. When adding a new page, you can define the category with the help of the ‘Advanced Custom Fields’ plugin.
I can get the content of those custom fields using
<?php the_field('categorie'); ?>
or
<?php get_field('categorie'); ?>
(depending on the use of it).The original website has a list at the bottom of the page showing all the pages sorted by category. I would like to make this dynamic so that you don’t have to add the page manually when you add a new page to your site.
I would like to make a separate array for each category. In other words: the first array contains all pages with category 1, the second array contains all pages with category 2 etc.
This might not be the easiest way, but it will help me with some other functions I need to add to the website.However, I have no clue on how to store the pages in an array based on category. And I also have no clue on how to show a list with the names of the pages in that category.
I guess it should be something like this:
if (get_field('categorie') == 'condition1') { add page to array1 } else if (get_field('categorie') == 'condition2') { add page to array2 } etc.
But like I said, I have no clue on how to get it working.
I am no PHP expert so I hope someone can help me.
Much thanks in advance
- The topic ‘Store pages in array if "condition"’ is closed to new replies.