Jump to content

Manual sort with selector on page field


PWaddict
 Share

Recommended Posts

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 } ?>

 

Link to comment
Share on other sites

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 } ?>

 

Link to comment
Share on other sites

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
};

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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) {
	// ...
}

?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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...