Home › Forums › Front-end Issues › Filter by Date Piker
Hello!!
I have a problem: I need to add a filter associated to a Custom Field.
I installed the plugin “Advanced Custom Fields” and I created a field type “Date Picker” with key “Fecha_de_Estreno“, until here everything ok.
Now I want to add in my theme a new filter associated with this new field and do not know how I can do.
My theme currently has several filters
Sort By:
Date
Title
Site Rating
User Rating
Fecha de Estreno (this is what I added but does not work)
I have a template called “dropdown-filter.php” with this code:
<?php
global $gp_settings;
// Dropdown Filter URLs
$page_url = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
$short_page_url = $_SERVER["REQUEST_URI"];
$cat_id = get_query_var('cat');
$category_url = get_category_link($cat_id);
if( is_search() ) {
$category_url = $category_url.'?s='.esc_html($s).'&';
} else {
$term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
$tax_name = get_taxonomy(get_query_var('taxonomy'));
if( $tax_name && ! $tax_name->hierarchical ) {
if( $tax_name->name == 'release_date' ) {
$cat_slug = $theme_review_tag_1_slug;
} elseif( $tax_name->name == 'genre' ) {
$cat_slug = $theme_review_tag_2_slug;
} elseif( $tax_name->name == 'rating' ) {
$cat_slug = $theme_review_tag_3_slug;
} elseif( $tax_name->name == 'director' ) {
$cat_slug = $theme_review_tag_4_slug;
} elseif( $tax_name->name == 'producer' ) {
$cat_slug = $theme_review_tag_5_slug;
} elseif( $tax_name->name == 'screenwriter' ) {
$cat_slug = $theme_review_tag_6_slug;
} elseif( $tax_name->name == 'studio' ) {
$cat_slug = $theme_review_tag_7_slug;
} elseif( $tax_name->name == 'starring' ) {
$cat_slug = $theme_review_tag_8_slug;
} else {
$cat_slug = $tax_name->name;
}
} else {
if( get_option("permalink_structure") ) {
$cat_slug = $theme_review_cat_slug;
} else {
$cat_slug = "review_categories";
}
}
if( get_option("permalink_structure") ) {
$category_url = home_url() . '/'. $cat_slug . '/' . $term->slug . '/?';
} else {
$category_url = home_url() . '?' . $cat_slug . '=' . $term->slug . '&';
}
}
?>
<div id="dropdown-filter">
<div class="order-by-text"><?php _e('Sory By', 'gp_lang'); ?>:</div>
<form class="order-by-form">
<select>
<option value="<?php echo $category_url; ?>orderby=meta_value&meta_key=fecha_de_estreno"<?php if(preg_match('/orderby=meta_value&meta_key=fecha_de_estreno/', $page_url)) { ?> selected<?php } ?>><?php _e('Fecha de Estreno', 'gp_lang'); ?></option>
<option value="<?php echo $category_url; ?>orderby=date"<?php if(preg_match('/orderby=date/', $page_url)) { ?> selected<?php } ?>><?php _e('Date', 'gp_lang'); ?></option>
<option value="<?php echo $category_url; ?>orderby=title"<?php if(preg_match('/orderby=title/', $page_url)) { ?> selected<?php } ?>><?php _e('Title', 'gp_lang'); ?></option>
<?php if($gp_settings['orderby_site_rating'] == true) { ?><option value="<?php echo $category_url; ?>gdsr_sort=review&gdsr_multi=<?php echo $theme_site_multi_rating_id; ?>"<?php if(preg_match('/gdsr_sort=review/', $page_url)) { ?> selected<?php } ?>><?php _e('Site Rating', 'gp_lang'); ?></option><?php } ?>
<?php if($gp_settings['orderby_user_rating'] == true) { ?><option value="<?php echo $category_url; ?>gdsr_sort=rating&gdsr_multi=<?php echo $theme_user_multi_rating_id; ?>"<?php if(preg_match('/gdsr_sort=rating/', $page_url)) { ?> selected<?php } ?>><?php _e('User Rating', 'gp_lang'); ?></option><?php } ?>
</select>
</form>
<div class="order-text"><?php _e('Order', 'gp_lang'); ?>:</div>
<form class="order-form">
<select>
<option value="<?php if(preg_match('/orderby=/', $page_url) OR preg_match('/gdsr_sort=/', $page_url) OR !get_option("permalink_structure")) { ?><?php echo $short_page_url; ?>&order=desc&gdsr_order=desc<?php } else { ?><?php echo $short_page_url; ?>?order=desc<?php } ?>"<?php if(preg_match('/order=desc/', $page_url)) { ?> selected<?php } ?>><?php _e('Descending', 'gp_lang'); ?></option>
<option value="<?php if(preg_match('/orderby=/', $page_url) OR preg_match('/gdsr_sort=/', $page_url) OR !get_option("permalink_structure")) { ?><?php echo $short_page_url; ?>&order=asc&gdsr_order=asc<?php } else { ?><?php echo $short_page_url; ?>?order=asc<?php } ?>" <?php if(preg_match('/order=asc/', $page_url)) { ?> selected<?php } ?>><?php _e('Ascending', 'gp_lang'); ?></option>
</select>
</form>
</div>
I have added this
<option value="<?php echo $category_url; ?>orderby=meta_value&meta_key=fecha_de_estreno"<?php if(preg_match('/orderby=meta_value&meta_key=fecha_de_estreno/', $page_url)) { ?> selected<?php } ?>><?php _e('Fecha de Estreno', 'gp_lang'); ?></option>
below this
<div id="dropdown-filter">
<div class="order-by-text"><?php _e('Sory By', 'gp_lang'); ?>:</div>
<form class="order-by-form">
<select>
but it does not work
The plugin (Advanced Custom Fields) support tells me I have to add something like this
http://www.advancedcustomfields.com/resources/field-types/date-picker/
but not that I have to do.
I have added different dates in the Date Piker of each post but not sorted correctly in the filter.
When I click on Fecha de Estreno (Custom Field) is ordered in the same way you sort by “Date” and this would have to order by the day of the Date Piker for each post
I do not know if I have to add something more
Eg: http://lafilmoteca.net/categoria/peliculas/
please help is very important for me
thank you very much
Hi @realroy
Thanks for all the code, but I have no idea what you are expecting it to do. You say:
but it does not work
Can you elaborate on this so I can provide clear advise?
Thanks
E
The topic ‘Filter by Date Piker’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.