Support

Account

Home Forums General Issues Saving an ACF value in a cookie

Solved

Saving an ACF value in a cookie

  • Hi there, can anyone tell me how to query a custom field and then save it in a cookie. Below is a snippet I use for the default permalink… not sure how to go about getting an ACF field.

    Snippet for permalink:

    $page_url = get_permalink($post->ID);
    	$url_cookie = "lp_permalink";
    	setcookie($url_cookie, $page_url, time() + (86400 * 30), "/");
    	wp_reset_postdata();

    What I have hacked up for the custom field:

    $page_title = get_field('content_heading')->the_field('content_heading');
    	$title_cookie = "lp_title";
    	setcookie($title_cookie, $page_title, time() + (86400 * 30), "/");

    As is evident, I’m no PHP guy… but I gave it my best shot.. can someone help?
    My field name is “content_heading”

    Thanks!

  • Change

    $page_title = get_field('content_heading')->the_field('content_heading');
    

    to

    $page_title = get_field('content_heading');
    
  • Awesome.. I was so close. Thanks for that. Sorry it took me a while to come back here!

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Saving an ACF value in a cookie’ is closed to new replies.