0

Well, let me get to the point, im trying to Display a specific category using the Wp favorites posts plugin this is what im adding $category_id = get_cat_ID('news'); but it doesn't seem to work it shows all category's on favorite posts instead of a certain specific category.

this is what im messing around with and i placed my category

<?php
foreach ( $favorite_post_ids as $o ) :
    $category_id = get_cat_ID( 'news' );
    $p = get_post( $o );
    if ( $p->post_status == 'publish' ) {?>

& this is the whole entire favorite posts box that makes it functional.

<div class="profile-box items-following">

    <h3><?php _e( 'fav posts', 'bd_lang' ); ?></h3>

    <div class="profile-content">

        <?php $favorite_post_ids = wpfp_get_users_favorites();
        if ( $favorite_post_ids ) { ?>

            <?php foreach ( $favorite_post_ids as $o ) : $p = get_post( $o );
                if ( $p->post_status == 'publish' ) { ?>    

                    <div class="profile-item">

                        <!--Begin Image-->
            <?php if ( has_post_thumbnail( $o ) ) { ?>                  
                            <div class="post-thumbnail">
                                <a href="<?php get_permalink( $o ); ?>" title="<?php echo $p->post_title; ?>">
                <?php $image = vt_resize( get_post_thumbnail_id( $o ), '', 50, 0, true ); ?>
                                    <img src="<?php echo $image[url]; ?>" width="<?php echo $image[width]; ?>" height="<?php echo $image[height]; ?>" alt="<?php if ( get_post_meta( get_post_thumbnail_id( $o ), '_wp_attachment_image_alt', true ) ) {
                    echo get_post_meta( get_post_thumbnail_id( $o ), '_wp_attachment_image_alt', true );
                } else {
                    echo $p->post_title;
                } ?>" />        
                                </a>                
                            </div>                  
            <?php } ?>
                        <!--End Image-->

                        <a href="<?php echo get_permalink( $o ); ?>" title="<?php echo $p->post_title; ?>"><?php echo $p->post_title; ?></a>

                    </div>

        <?php } endforeach; ?>

        <?php } else { ?>

            <div class="profile-item">
                <strong><?php _e( 'Your are not currently following any items.', 'bd_lang' ); ?></strong>
            </div>

<?php } ?>

    </div>

</div>

closed as off-topic by kaiser Aug 1 '14 at 22:57

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

1

This should do what you want:

$have_favorite_posts = false;
$favorite_post_ids = wpfp_get_users_favorites();
$cat = get_category_by_slug('news')->cat_ID;
// or if you want to use the category name (as tried in your code)
// $cat = get_cat_ID('News');
if (! empty($favorite_post_ids)) {
    $fp_query = new WP_Query(array(
            'cat' => $cat,
            'post__in' => $favorite_post_ids,
    ));
    if ($fp_query->have_posts()) {
        $have_favorite_posts = true;
        while ($fp_query->have_posts()) : $fp_query->the_post();
            if ('publish' === get_post_status(get_the_ID())) { ?>
                <div class="profile-item">
                    <!--Begin Image-->
                    <?php if (has_post_thumbnail()) { ?>
                        <div class="post-thumbnail">
                            <a href="<?php echo get_permalink(); ?>" title="<?php the_title(); ?>">
                                <?php
                                    $image = vt_resize(get_post_thumbnail_id(), '', 50, 0, true);
                                    $url = $image[url];
                                    width = $image[width];
                                    $height = $image[height];
                                    $alt = get_post_meta(get_post_thumbnail_id(), '_wp_attachment_image_alt', true);
                                    if (! $alt) $alt = get_the_title();
                                ?>
                                <img src="<?php echo $url; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>" alt="<?php echo $alt; ?>" />
                            </a>
                        </div>
                    <?php } ?>
                    <!--End Image-->
                    <a href="<?php echo get_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
                </div>
            }
        endwhile;
    }
}
if (! $have_favorite_posts) { ?>
    <div class="profile-item">
        <strong><?php _e('You are not currently following any items in this category.', 'bd_lang'); ?></strong>
    </div>
<?php } ?>

// EDIT: now, you also see the not following message if there are favorite posts but not in the given category.

  • thanks alot ill try it right now and ill let you know how it turned out thanks once more. – DeadArtcore Apr 24 '13 at 22:50
  • basically for the first time, the msg no posts have been found is seen but after you unfollow the post it blank – DeadArtcore Apr 25 '13 at 0:57
  • also one more thing how can i duplicate the same favorite posts wpfp_get_users_favorites and from that duplicate create another but instead that i can make a favorite photos and its specified for photos only not favorite posts – DeadArtcore Apr 25 '13 at 2:35
  • I updated my answer and now the not following message should be displayed correctly. As for your other question: once again, please post this as a new question. – tfrommen Apr 25 '13 at 6:37
  • thanks once more for the great help, i have already created a duplicate so it was a success thanks for the amazing help – DeadArtcore Apr 25 '13 at 13:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.