• I have the following code in a custom page:

    <?php $catposts=get_posts'category=3&numberposts=-1&orderby=date&order=desc'); ?>
    
    <?php foreach($catposts as $single): ?>
    		....Do something
    <?php   endforeach; ?>

    Problem is that on a large post amount, an “out of memory” error is issued; moreover, I just need some first tenth records to be displayed.
    So I have added a filter in functions.php, that filters the recordset by post title:

    function arabunu ()
    {
    global $wpdb;
    $sorgu= "AND $wpdb->posts.post_status='publish' AND $wpdb->posts.post_type='post' AND $wpdb->posts.post_title LIKE 'BLABLABLA%'";
    return $sorgu;
    }

    inserting the add filter before the query:

    <?php add_filter('posts_where', 'arabunu');?>
    <?php $catposts=get_posts ('category=3&numberposts=100&orderby=date&order=desc'); ?>

    Unfortunatelly the filter is not applied. Any help?

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

    (@blutarsky)

    Hello?

    Thread Starter Blutarsky

    (@blutarsky)

    Help?

    Thread Starter Blutarsky

    (@blutarsky)

    I have tried the following:

    add_filter('posts_where', create_function('$a','global $wpdb; $rrr = " AND $wpdb->posts.post_status=\'publish\' AND $wpdb->posts.post_type=\'post\' AND $wpdb->posts.post_title LIKE \'blblbla%\'"; return $a . $rrr;'));
    
    $catposts=query_posts('numberposts=15'); ?>

    The filter works but the numberposts parameter is ignored… any hint?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Selecting posts by title’ is closed to new replies.