Found a solution:
add_filter( 'facetwp_preload_url_vars', function( $url_vars ) {
//get the id of the current page
$url="http://" . $_SERVER[ 'HTTP_HOST' ] . $_SERVER[ 'REQUEST_URI' ];
$current_post_id = url_to_postid( $url );
//get the offer_type (custom field) from the current page id
$offer_id = get_field('offer_type', $current_post_id); //returns an id
//get the taxonomy slug from the offer_id
$term = get_term( $offer_id, $taxonomy );
$slug = $term->slug;
//preselect the offer_type facet
if ( empty( $url_vars['offer_type'] ) ) {
if($slug) {
$url_vars['offer_type'] = [$slug];
}
}
return $url_vars;
} );
Related Posts:
- How to make a image-size selected by default in Media upload – WP v3.5
- Hide main div if wp_nav_menu is empty
- How to draw media details for Isotope gallery using Photoswipe
- Add Useragent to the body class?
- Remove wp-mediaelement.css from wp_head
- add_filter to post-gallery and remove all ‘s?
- Set the transport of the Customizer ‘header_image’ core setting to ‘postMessage’
- show limited tags in an article
- delete an array element when its date expires
- Using a function written in my functions.php file within the header.php file
- Disable External Pingacks on WordPress Posts and Only Allow ‘Self Pings’
- Woocommerce: Is it possible to overide the settings for allowing to purchase out of stock products [closed]
- javaScript in section of WP API
- WordPress Redirect: Default Password Reset URL [duplicate]
- Function not working at one place
- Create another “Display Site Title and Tagline” checkbox, “Header Text Color” setting and control
- How to remove or change the “W” icon in “My Sites”?
- How to prevent WP_Query function from returning all posts when empty?
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- Woocommerce: hook action/filter I could use to add variation id and price with each attribute opt on WooCommerce Rest api
- Firing schema via code in functions.php doesn’t work
- A non-numeric value encountered in /wp-includes/functions.php on line 68
- foreach loop still echoes array
- dynamic dependent select dropdown
- Generating an nonce for Content Security Policy and all scripts – How to make it match/persist for each page load?
- getting logged in user info (wp-load.php) from parent directory
- Blog posts repeat
- Ajax load more button for comments wordpress
- Update user profile information from functions.php
- wp-comments-post.php file returns a blank page
- Add .htm extention to a custom taxonomy
- Custom gallery in wp3.5
- How can I modify footer when footer.php calls to another file?
- Noscript not working as it should in wordpress site
- How to fix this warning:call_user_func_array() expects exactly 2 parameters, 1 given in D:\wamp\www\…….\wp-includes\class-wp-hook.php on line 286
- How to set the WordPress logo programmatically with PHP
- How to use theme function in post/page?
- esc_url( ) won’t use https
- Function won’t run onclick using Ajax
- Content filter won’t work
- Where is this function’s callback getting its arguments from?
- Why does the post_type_link hook everything twice?
- Warning: in_array() null given in PHP function
- Use post ID in functions.php file adminside
- How to: Conditionally Enqueue JS and Stylesheets, for Custom Post Type (Single and Archive Templates)
- List all blogs, but exclude the main site
- use loop to return blog details
- How can I count ACF sub_field with a certain value
- change the default order of posts only for specific categories
- Fetching Initials of the Commentator in the WordPress Website
- Adding function to child theme’s function.php
- Problem with adding custom CSS class to image in ACF Photo Gallery plugin [closed]
- Custom posts password protect
- How to get post category list as select in front-end?
- How to use functions [closed]
- Splitting the_content() by size?
- Extract and display user infromation on an automatically created page
- Is it legal to redefine wp_password_change_notification in a mu plugin?
- How can I assign separate stylesheets to different pages?
- Function to call either single post or category
- WP Container Displaying Only on First Page of Archive
- Updating Metadata with Shortcode
- can’t load .po file in functions.php
- WP-Bakery – Add custom colors to buttons with template colors
- Woocommerce – Exclude variation attribute on specific variation
- How do I add a function to parent theme
- Are there any drawbacks on opening a session_start in functions.php and header.php?
- Create shortcode for metabox gallery
- Add Pre-Defined Value to Click Counter in WordPress
- How can I redefine WordPress wp-content directory programmatically?
- Trim Titles Only On Some Pages
- Child theme overirde template-tags in a theme built on underscores in inc/template-tags
- Delete post meta by serialized meta value
- Custom meta box is not displaying value showing tag as empty
- Menu not updating for logged in users after redirect
- Create a temporal post
- PHP/CSS: Shortcode won’t display correctly, and only displays in the head (before content)
- Add parent menu item in sub-menu in custom nav_walker
- WordPress load javascript file if something… (after the page is loaded)
- Add class for the_post_thumbnail_caption()
- Getting page / post URL on publish and / or update
- Weird Behaviour: Not all WordPress Posts appearing
- Save the outputted image into the Media Library, with a different filename and extension
- Custom Taxonomy as Link
- How to fix blank pagination links?
- main menu page redirects to user ID
- How to have Function of a plugin using global vars into a shortcode?
- Adding ID to a Listing but not inside WP_Query while
- adsense code showing on random post thumb
- How can I clear the theme mod settings?
- Cant get theme to change footer color through theme customizer
- How to extend the page editor?
- How to return a Boolean for a page that is a subpage thru its name?
- I need a button to appear when not loged in and another when logged in, I need help fixing code PLEASE!
- Undefined variable notice [closed]
- How to hide .js files on wordpress website using php or wp plugins or any? [closed]
- WP Custom tables query
- Automatically change insurance quantity based on cart total [closed]
- How to pass value to add_filter wpcf7_form_tag from another function?
- hiddenQuestions.find is not a function