WP Favorite Posts
WP_Set_Post_Terms (2 posts)

  1. Brandon Dennis
    Posted 2 years ago #

    I'm trying to add a wp_set_post_terms function to work with the WP Favorite Posts plugin. The idea is that when a user adds a post to favorites, the function would add/change the post tag to "Taken". When I display the posts on the main list page (the page that lists all posts), I'll filter it to exclude all posts with the "Taken" tag. I've pieced together the following script, but I'm not sure where to put it:

    function wp_set_post_terms( $post_id = 0, $tags = 'taken', $taxonomy = 'post_tag', $append = false ) {
    $post_id = (int) $post_id;

    if ( !$post_id )
    return false;

    if ( empty($tags) )
    $tags = array();

    if ( ! is_array( $tags ) ) {
    $comma = _x( ',', 'tag delimiter' );
    if ( ',' !== $comma )
    $tags = str_replace( $comma, ',', $tags );
    $tags = explode( ',', trim( $tags, " \n\t\r\x0B," ) );

    // Hierarchical taxonomies must always pass IDs rather than names so that children with the same
    // names but different parents aren't confused.
    if ( is_taxonomy_hierarchical( $taxonomy ) ) {
    $tags = array_unique( array_map( 'intval', $tags ) );

    return wp_set_object_terms( $post_id, $tags, $taxonomy, $append );

    I've tried putting it in the wp-favorite-posts.php file directly below the function that adds the post to favorites as well as in the post.php found in wp-admin. No luck in either case. Any help would be much appreciated.

    Brandon Dennis


  2. Brandon Dennis
    Posted 2 years ago #

    Alternatively, I'd just like a way to show all posts on a page EXCEPT for posts that have been marked as favorite.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WP Favorite Posts
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.