How to feature an entry using PHP

If you want to modify whether an entry is featured using PHP instead of by starring an entry in WordPress Dashboard, you can do so by using the gravityview_featured_entries_enable filter.

Please note that entries featured using this method won't be able to move to the top even if the View is set to Move Featured Entries to top.

The parameters passed to gravityview_featured_entries_enable

  • $enable_featured_entry (boolean) Whether to enable featured entries for this entry
  • $view (GravityView_View) The current GravityView_View instance
  • $entry (array) Gravity Forms entry array

By returning false, the $entry will not be featured. By returning true, the entry will be featured.

Some sample code:

add_filter( 'gravityview_featured_entries_enable', 'modify_gravityview_featured_entries_enable', 10, 3 );

/**
 * Enable or disable featured entries for this entry
 *
 * @param boolean $is_featured Whether to enable featured entries for this entry
 * @param GravityView_View $view The current GravityView_View instance
 * @param array $entry Gravity Forms entry array
 *
 * @return boolean $is_featured Whether to enable featured entries for this entry
 */
function modify_gravityview_featured_entries_enable( $is_featured, $view, $entry ) {

	// If you want to feature a list of entry IDs, you can do so like this
	if ( in_array( $entry['id'], array( 12, 49, 388 ) ) ) {
		return true;
	}

	// Otherwise, return the default
	return $is_featured;
}

Read here how to add these code samples to your website: Where to put code samples.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us