Forums

[resolved] Can't Get the Terms from My Posts! (6 posts)

  1. magblogapi
    Member
    Posted 1 year ago #

    (I'm actually using 3.0.3, but the popup can't count that high).

    In any case, I have written a plugin that lists posts within a page or a post, so the implementor can mix static content with dynamic. No big deal, but very, very useful.

    I need to extend this to allow posts to be listed if they are part of a series, in the excellent organize-series plugin. I already have this working for categories. I haven't (yet) extended it to tags, but I need to do this for series.

    Here's the code of what I am trying:

    $posts = get_posts(array('numberposts' => -1));
    foreach ( $posts as $mypost )
    	{
    	$should_list = false;
    	if ( function_exists ( taxonomy_exists ) && taxonomy_exists ( 'series' )
    		&& function_exists ( get_series_ID )
    		&& is_array ( $options['series_list'] )
    		&& count ( $options['series_list'] )
    		)
    		{
    		$terms = wp_get_object_terms ( $my_post->ID, 'series' );
    		foreach ( $options['series_list'] as $series_term )
    			{
    			$ser_ID = get_series_ID ( $series_term );
    			if ( $ser_ID )
    				{
    				$series_term = $ser_ID;
    				}

    The problem is in this line:

    $terms = wp_get_object_terms ( $my_post->ID, 'series' );

    The 'series' term exists, and lots of posts are tagged with various tags.

    However, I ALWAYS get an empty array as a function return from wp_get_object_terms. I have tried wp_get_post_terms, everything.

    The $my_post is not within the loop. It can't be. We're already inside another post.

    I'm sure that I'm making some boneheaded mistake. Anyone able to set me straight?

  2. magblogapi
    Member
    Posted 1 year ago #

    There's an error. I went back and twekaed a bit.

    my_post should be mypost (It is in my code).

  3. magblogapi
    Member
    Posted 1 year ago #

    Nevermind. I figured it out.

    File under "D'oh!'

  4. Francis Crossen
    Member
    Posted 1 year ago #

    Having the same problem here... care to share how you fixed this?

    ;-)

    Thanks,

  5. magblogapi
    Member
    Posted 1 year ago #

    This line was the problem:

    $terms = wp_get_object_terms ( $my_post->ID, 'series' );

    That should have been $mypost

    Completely my boneheaded problem.

  6. Francis Crossen
    Member
    Posted 1 year ago #

    Sorry - I didn't read your post properly.
    Fixed my issue too - another bonehead problem!

    Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic