Jump to content

Recommended Posts

Posted

Hi,

I have a select field called 'show' and it has two options to select:

1=CTRL Daily
2=Channelgregnet

How do you filter posts by the select field?

 

Thanks.

Posted

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
Posted

Thanks for the help. It's what I was looking for.

<?php foreach($page->children("show.label=CTRL Daily") as $post) :?>
    		<?php echo $post->title;?>
    		<?php echo $post->ad_copy;?>
		<?php endforeach;?>

 

  • Like 1
Posted

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...