This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Method 1: simple foreach loop | |
$favorites = get_user_favorites(); | |
if ( isset($favorites) && !empty($favorites) ) : | |
foreach ( $favorites as $favorite ) : | |
// You'll have access to the post ID in this foreach loop, so you can use WP functions like get_the_title($favorite); | |
endforeach; | |
endif; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Enable Categories for the Location Post Type | |
*/ | |
function enable_categories_in_locations() | |
{ | |
register_taxonomy_for_object_type('category', 'location'); | |
} | |
add_action( 'init', 'enable_categories_in_locations' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Display a list of the 10 most favorited posts | |
* @see https://wordpress.org/plugins/favorites/ | |
*/ | |
$favorites_query = new WP_Query(array( | |
'post_type' => array('post'), | |
'posts_per_page' => 10, | |
'meta_key' => 'simplefavorites_count', | |
'orderby' => 'meta_value_num', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter('simplefavorites_user_list', 'filter_favorites_user_list', 10, 3); | |
function filter_favorites_user_list($output, $users, $anonymous_count) | |
{ | |
$output = '<ul>'; | |
foreach($users as $user){ | |
$output .= '<li><a href="' . site_url() . '/members/' . $user->user_login . '">' . $user->display_name . '</a></li>'; | |
} | |
$output .= '</ul>'; | |
$output .= '(+' . $anonymous_count . ' Anonymous Users)'; | |
return $output; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( is_user_logged_in() ) : | |
the_favorites_button(); | |
else : | |
// Place any logged-out messaging/JS here | |
?> | |
<p>Please log in to save favorites</p> | |
<?php endif; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Place this code in your theme's functions.php file | |
/** | |
* First, add the column to the view | |
* Change the post type by substituting 'post' with the post type | |
* Ex: a post type of recipe would be manage_recipe_posts_columns | |
*/ | |
add_filter('manage_post_posts_columns', 'add_favorite_count_column'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Remove Posts from Being Displayed in the Nested Pages List | |
* @param $args - array of WP_Query arguments | |
* @see wp-nested-pages/app/Entities/Listing/Listing: Line 274 | |
*/ | |
add_filter('nestedpages_page_listing', 'remove_from_nested_pages'); | |
function remove_from_nested_pages($args) | |
{ | |
$remove_ids = array(); // Array of Post IDs to exclude |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Allow a user to email a list of favorites | |
* Place in functions.php and update to suit your specific form and needs | |
* @link https://www.gravityhelp.com/documentation/article/gform_notification/ | |
*/ | |
add_filter( 'gform_notification_1', 'email_favorites_list', 10, 3 ); | |
function email_favorites_list($notification, $form, $entry) | |
{ | |
// Get the user's favorites and create a list | |
$favorites = get_user_favorites(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter('simple_locator_result', 'location_result', 10, 3); | |
/** | |
* Filter the individual results in the list | |
* @param string $output – HTML to return | |
* @param object $result - SQL result. If custom fields have been added to the query using the JOIN filter, they will be available | |
* @param int $count - current result count | |
*/ | |
function location_result($output, $result, $count) | |
{ | |
$out = '<li>'; |
OlderNewer