I found out you could identify ajax requests by the following if-statement
if (defined('DOING_AJAX') && DOING_AJAX)
So problem solved using
add_action('init', 'set_global_pixelcapival');
function set_global_pixelcapival() {
if (defined('DOING_AJAX') && DOING_AJAX) {
} else {
global $pixelcapival;
$pixelcapival = pixelcapival();
global $prev_pixelcapival;
$prev_pixelcapival="";
if(isset($_COOKIE['pixelcapival'])) {
$prev_pixelcapival = $_COOKIE['pixelcapival'];
}
setcookie('pixelcapival', $pixelcapival, time() + 1200, "https://wordpress.stackexchange.com/");
}
}
Related Posts:
- Add class to all meta boxes for a custom post type
- what is correct way to hook when update post
- Using register_activation_hook in classes
- Custom plugin: Trying to show saved data on frontend
- Pass a PHP variable to another file
- Remove Woocommerce product link
- Check php version before theme activation
- How can I remove “Proudly powered by WordPress” from twentyeleven without modifying footer.php?
- How can I hook into and edit the text of a wp_nav_menu tag?
- WooCommerce: How to display item meta data in email confirmation using woocommerce_order_item_meta_end
- Check if page parent has certain template
- How to remove “out of stock” variation options from size dropdown in woocommerce?
- Prevent publish status/date saved on transition_post_status hook
- How to Remove a Filter from the Admin List Table?
- Woocommerce, recognize the loop of related products
- Is $hook a global variable in WordPress
- Executing `createimagefrompng()` from save_post hook (or equivalent hook)
- Getting my head round WordPress filter
- Delete option value from array using update_option()
- How to set a custom path, for ajax image upload folder in admin?
- When using the_author hook, how can I determine the PHP file that generates each call to `the_author()`?
- Locating Global Variables
- Pass PHP variable to JavaScript without inline JS
- Count the number of times the search form template gets included on a page
- How to add a second ‘place order’ button in WooCommerce [closed]
- How to do multiple searches (with logical OR) in WP_Query in hook pre_get_posts?
- Using a variable in is_page(array())
- Handling Body class based on Template
- How to load a template-part based on a url wildcard?
- How to put a variable in a instance in the widget
- get_term_link() returns correct – But illogical error-messages disturb
- ajax, right way to do it and make it works?
- Sending data from custom inputs in WordPress comment form in the admin notification email
- Reload part of checkout on changed shipping method
- Trying to build simple deposit code that hooks into woocommerce
- Add a product to checkout via form
- Why ajax doesn’t work on certain wordpress hooks and reload the page instead?
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- user_profile_update_errors hook not executing
- Set meta field to publish date + 2 weeks
- WordPress Gravatar filter is removing my custom attributes
- Return a numerical function value in Customizer controls
- Adding widgets to my plugin page instead of WordPress dashboard
- How to modify a global variable in a function and use it on another function?
- edit_comment_link is not showing for comment author
- Adding function to Genesis genesis_header [closed]
- Modify custom field input data before creating a new post
- Should `wp_login` be used since it’s deprecated?
- Password minimum length in personal subscription [closed]
- How to use a custom hook
- Run a code only on theme activation only during first activation
- Theme activation hook in php class
- Creating WordPress Shortcode with Variable
- Theme not calling Jquery properly
- How to put a form with php code into a variable or shortcode?
- persist a variable set in header.php all the way down to footer.php
- What is the alternative code to if (isset ($_POST) && !empty ($_POST) to avoid warnings?
- How can I hook into the wp_mail function used by BackWPup?
- Can not add admin notices from the edit_user_profile_update hook (notices not being displayed)?
- Changing the order of custom fields in the dashboard for Woocommerce variable products [closed]
- javascript variable to wordpress php variable
- How to reference PHP in Javascript
- echo var into wp_query
- Must filter functions receive all arguments passed to them?
- Generate a QR code when creating a new WordPress user
- Filter wordpress posts without searching the keywords in the post content
- How to send a php var to jQuery Ajax call with two different file
- Variation prices breakdown only for single product page
- Display custom field value in woocommerce variable product via jQurey
- Add custom field on admin dashboard comments / reviews
- Preserving backslashes in post_content
- WordPress How do I pass a variable from one add_action to another?
- Best way to use variables in multiple functions?
- How to edit post meta data before publishing the post it self wordpress?
- Enqueue assets from multiple directories using add_action/do_action
- Adding new divs with custom classes to products on WooCommerce shop page [closed]
- Call a single function on two different methods with hooks
- Discount in the specific product title using keyword ( Woocoommerce )
- get Woocommerce product format json for WP_Query
- Is there an option to execute javascript file only on plugin activation
- How do I remove an action hook inside a class that is called by another class?
- Help hooking into user_register
- Hook into all password resets in WordPress and get password before hashing?
- Why transition_post_type hook is called twice for the same post?
- Clone the “proceed to cart” button and place it above checkout on the cart page, but only appear display size is 320px
- Passing link parameter values to form
- Custom Taxonomy Link Text Echo Name Not Slug
- WordPress HTML Helper
- how to add number value in front for variable [closed]
- Difference in Get Variable Location
- How to add custom checkout field in user details mail template
- For each loop will not append to the_content hook
- Import and use a variable in additional settings of Contact Form 7 [closed]
- Assign new post author IF another user in custom field on post transition
- Create and publish a new post every Monday, listing the post titles and links to the posts published during the previous week
- WP query with variables gives no result for specific user
- understanding wp_next_scheduled
- transition_post_status hook, works – but not if the post is new
- Guests comment form – prevent duplicate email addresses
- Woocommerce – add tracking code to another email template