Forums

Query posts by keyword (2 posts)

  1. barna
    Member
    Posted 1 year ago #

    Hi!

    I would like to get posts by keyword using query_posts.
    So, how can I query posts, that contain "big dog" as content?

    Thanks.

  2. vtxyzzy
    Member
    Posted 1 year ago #

    Use a filter to add a WHERE condition:

    function mam_posts_where ($where) {
       global $mam_global_where;
       if ($mam_global_where) $where .= " $mam_global_where";
       return $where;
    }
    add_filter('posts_where','mam_posts_where');
    $mam_global_where = " AND $wpdb->posts.post_content LIKE '%big dog%'";
    query_posts(your args here);
    $mam_global_where = '';  // Turn the filter off!

Topic Closed

This topic has been closed to new replies.

About this Topic