Jump to content

How do you filter posts by select field?


OpenBayou
 Share

Recommended Posts

I am not sure exactly what you want to do, but if for example you want to show the 10 most recent posts with their titles and summaries, I would use the selector to get the pages/posts as the children of the Posts parent, so something like this:

foreach($page->children("show=1, limit=10, sort=-published_date") as $post) {
    // output $post->title, $post->summary etc for each post
}

Is that what you are looking for?

BTW, I would use the key of the "show" options field, rather than the label, but it's really up to you.

  • Like 1
Link to comment
Share on other sites

I always do something like this:

$pages = $page->children("show.label=CTRL Daily")
if(count($pages) && is_array($pages)) {
	foreach($pages as $post) //etc...
} else {
	error_log("Custom NOTICE: Options Fieldtype called XYZ contains no label 'CTRL Daily'!");
}

This way you will have a clue what goes on if someone (including you) happens to rename the option. Note, that even using IDs has its drawback: the order of labels can be changed as well even if they are exactly the same.

  • Like 1
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...