WordPress.org

Ready to get started?Download WordPress

Forums

$post->post_title in filter function (4 posts)

  1. slavix
    Member
    Posted 5 years ago #

    I am having problems accessing $post->post_title in a filter function inside my plugin. The function gets called from wp-icludes/link-template.php get_ajacent_post()

    ...
    $where = apply_filters( "get_{$adjacent}_post_where", $where, $in_same_cat, $excluded_categories );
    ...

    this is relevant plugin code

    function filter_next_post_where($where) {
    	return "WHERE p.post_title > '".$post->post_title."' AND p.post_type = 'post' AND p.post_status = 'publish' AND tt.taxonomy = 'category'";
    }
    add_filter('get_next_post_where',  'filter_next_post_where');

    The filter function is supposed to replace default where clause in post query but for some reason $post->post_title resolves to empty.
    function returns
    WHERE p.post_title < '' AND p.post_type = 'post' AND p.post_status = 'publish' AND tt.taxonomy = 'category'
    The function is called from within the loop.. what am I missing?

  2. slavix
    Member
    Posted 5 years ago #

    Its been over 2 months since I posted this.. Can somebody please answer me?

    thanks,
    Slava

  3. easysleeper
    Member
    Posted 5 years ago #

    Not sure but you could try placing the_title($echo = false); or the_title('','',false); as the first line in the function.

  4. slavix
    Member
    Posted 5 years ago #

    thanks. I tried both
    the_title($echo = false); and the_title('','',false);
    but in both cases it comes back empty...

    function filter_previous_post_where($where) {
       	return "WHERE p.post_type = 'post' AND p.post_status = 'publish' AND tt.taxonomy = 'category' AND  p.post_title < '" . mysql_real_escape_string(the_title($echo = false)) . "'";
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.