Views is a WordPress plugin that lets you easily display content on your website's front-end in any way you choose.
Views User Guides include detailed documentation for creating lists of content, templates for content and archive page and also explain how to create parametric searches for any content type.
When you ask for help or report issues, make sure to tell us the versions of the Toolset plugins that you have installed and activated.
Viewing 15 topics - 2,371 through 2,385 (of 3,151 total)
Problem: I would like to create a parametric search View that allows users to filter a list of posts by post status, using a dropdown select filter.
Solution: It is not currently possible to create front-end filters for post status. Other workarounds proposed in the past have limitations that are not easily overcome with custom code. Instead, the most practical approach is to create a custom select field that includes values corresponding to each possible post status. Copy the actual post status information into the value of this custom field for each post, and set up a parametric search View that filters upon this custom field.
In this case the posts are created in Forms, and a generic select field is used to allow the User to choose a post status for the created post. There is a custom code snippet using the cred_submit_complete API to programmatically set the post status after the Form is submitted. We can tap into that event hook to also set the custom field value programmatically with update_post_meta:
add_action('cred_submit_complete', 'my_save_draft',10,2);
function my_save_draft($post_id, $form_data)
{
// if a specific form
if ($form_data['id'] = array(737,521))
{
if (isset($_POST['post_stat']))
{
// update post status
$my_post = array(
'ID' => $post_id,
'post_status' => $_POST['post_stat'],
);
wp_update_post($my_post);
// add / update post-status custom field value
update_post_meta( $post_id, 'wpcf-post-status', $_POST['post_stat']);
}
}
}