Home › Forums › Front-end Issues › Save select option on page refresh › Reply To: Save select option on page refresh
For the first question, I’m not sure how the value is being submitted so I’m assuming that $_GET[‘press’] is an array of the selected values, if this assumption is incorrect then you’ll need to alter that part to match the submitted value.
foreach ($years as $key => $value) {
foreach ($value as $year) {
?>
<option value="<?php echo $year; ?>"<?php
if (in_array($year, $_GET['press'])) {
echo ' selected="selected";
}
?>><?php echo $year; ?></option>
<?php
}
}
To show the posts for the selected years you need to create a pre_get_posts filter that alters the WP query. https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts. Check out some of these topics on using pre_get_posts https://support.advancedcustomfields.com/forums/search?bbp_search=pre_get_posts
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.