I am working on a slider where I will show some contents(featured image and excerpt) pulled from both posts and pages. I want to filter the posts/pages by a custom field called ‘slider’!
So if there are some pages and posts with ‘slider’ custom field only those will appear in the slider. Is it possible in wordpress? If it is then how?
Some guidance will be appreciated!
What you’re looking for is the class called WP_Query, has got a detailed explanation in the Codex. Take a look at the
post_type
argument which accepts an array, thus you can give it aarray( 'post', 'page' )
or any other post types that you want to fetch.Now the meta fetch could be done in two ways, either via the new
meta_query
argument (from 3.1 onwards I believe) ormeta_key
andmeta_value
which are deprecated since 3.1.Here’s a rough example (haven’t checked if this works):
Hope that makes sense. Cheers!
~ K