WordPress PHP function: HTML select element for posts & pages

Shortcode Attributes

Given the scope of the wp_query object, there are any number of queries that might be performed. We’ve included the most relevant search parameters to filter results.

status

There are 8 major post statuses that WordPress uses by default. The one that is likely to be used with a dropdown is publish (default). Other custom post types may also be used.

type

There are several post types that are readily available to users or internally used by the WordPress installation by default. The two that are most likely to be used are post and page (default).

parent

If displaying pages, you may nominate a parent page. Usage will display child pages.

exclude

The exclude attribute is a comma delimited list of posts or pages to exclude form results.

author

To display results by author, use the author ID or login username.

category

To limit posts by category, use the category ID.

tags

To limit return posts by tag, use the tags ID (multiple tags may be used).

order

You may order by ASC or DESC.

orderby

You may order by a large number of parameters . Most common are none, ID, author, title, name (the post slug), date, and rand (random).

format

If you include the date in the dropdown alongside the title, you may optionally alter the date presentation. While it defaults to the format defined by you in your WP installation,
you can alter with PHP’s date formatting.

date

To include the date alongside the post, use date="1".

number

By default we’ll return all posts, limit with number="10".

p

Wrap the result in paragraph tags with p="1". This navigates issues with WP shrotcodes and paragraph formatting.

style

Alter the style with the textbox here. For example, style="height: 30px; width: 400px;".

text

To change the text on the select box (Select Page), use text="Text in here".

length

Since post lengths can be long, you may truncate them with length="60". This uses the beliefmedia_split_dropdown_string() function.

cache

The wp_query can be an expensive operation. We cache the result for 8 hours by default. Alter in the shortcode or hardcode into the function.

Leave a Reply

Your email address will not be published. Required fields are marked *