Home Forums General Issues Check Relationship Field and Add/Remove


Check Relationship Field and Add/Remove

  • I’m trying to create a “bookmark” button of sorts … where when the user bookmarks a post, I save it to a Relationship field. If the user then unbookmarks it, I check the relationship field and remove it from the collection of relationships.

    Adding is easy. Removing is proving to be a pain in the butt and just destroys the entire array:

    $current_bookmarks = get_field( 'webinar_bookmarks', 'user_' . get_current_user_id() );
    	if ( in_array($webinar_post, $current_bookmarks) ) : // bookmarked, remove
    		$key = array_search($webinar_post, $current_bookmarks);
    		unset($current_bookmarks, $key);
    	else : // not bookmarked, add

    Is there a more official way of checking the current relationship array, and if it exists, removing it?


  • Here is the answer:

    $updated_bookmarks = $current_bookmarks;
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.