• slavix

    (@slavix)


    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?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter slavix

    (@slavix)

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

    thanks,
    Slava

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

    Thread Starter slavix

    (@slavix)

    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)) . "'";
    }

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘$post->post_title in filter function’ is closed to new replies.