PWaddict Posted May 11, 2018 Posted May 11, 2018 Using the below code for outputting content from a page field it doesn't get the manual sort order from the backend. What am I doing wrong? <?php foreach($page->my_page_field("category=1474, sort=sort") as $mpf) { ?> ... <?php } ?>
PWaddict Posted May 11, 2018 Author Posted May 11, 2018 Removing the selector from the loop it outputs the content on the correct manual sort order BUT I only need to output the content with the selector "category=1474". <?php foreach($page->my_page_field as $mpf) { ?> ... <?php } ?>
Zeka Posted May 11, 2018 Posted May 11, 2018 Does this code work as expected? $page->my_page_field->find('selector, sort=sort');
PWaddict Posted May 11, 2018 Author Posted May 11, 2018 1 hour ago, Zeka said: Does this code work as expected? $page->my_page_field->find('selector, sort=sort'); No.
wbmnfktr Posted May 11, 2018 Posted May 11, 2018 Can you please try this: <?php // get all pages in page field $resultsAll = $page->my_page_field; // filter $resultsByCategory = $resultsAll->filter('category=1474'); // sort $resultsSorted = $resultsByCategory->sort('sort'); foreach($resultsSorted as $result) { // whatever };
PWaddict Posted May 12, 2018 Author Posted May 12, 2018 2 hours ago, wbmnfktr said: Can you please try this: <?php // get all pages in page field $resultsAll = $page->my_page_field; // filter $resultsByCategory = $resultsAll->filter('category=1474'); // sort $resultsSorted = $resultsByCategory->sort('sort'); foreach($resultsSorted as $result) { // whatever }; It doesn't work. I guess this is not possible. I'll have to use "sort=name" or something similar.
gebeer Posted May 12, 2018 Posted May 12, 2018 Have you tried <?php // get all pages in page field sorted by manual sort order $resultsAllSorted = $page->my_page_field->sort('sort'); // filter $resultsCategory = $resultsAllSorted->filter('category=1474'); // loop foreach($resultsCategory as $result) { // ... } ?
PWaddict Posted May 12, 2018 Author Posted May 12, 2018 23 minutes ago, gebeer said: Have you tried <?php // get all pages in page field sorted by manual sort order $resultsAllSorted = $page->my_page_field->sort('sort'); // filter $resultsCategory = $resultsAllSorted->filter('category=1474'); // loop foreach($resultsCategory as $result) { // ... } ? Yep, it doesn't work.
wbmnfktr Posted May 12, 2018 Posted May 12, 2018 Ok... I don't have the exact same ProcessWire setup like you but sorting and filtering my page field's entries works with the example above. Is there a detail we miss at this point?
Zeka Posted May 12, 2018 Posted May 12, 2018 @PWaddict What type of page field type you have set up in the settings?
PWaddict Posted May 12, 2018 Author Posted May 12, 2018 9 hours ago, Zeka said: @PWaddict What type of page field type you have set up in the settings? Page field value type: Multiple pages PageArray Input field type: AsmSelect I decided to output all content from the page field without using a selector. Thank you all for trying to help.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now