WordPress.org

Ready to get started?Download WordPress

Forums

Not showing certain post filter the post (6 posts)

  1. aloncarmel
    Member
    Posted 7 years ago #

    Hello,
    I'm working on a plugin that filters certain posts from showing. How can i filter posts with a certain title from not showing up all together using a plugin in the post list?

  2. Kafkaesqui

    Posted 7 years ago #

    Something like this should do what you're after:

    function strike_title($where) {
    global $wpdb;
    $title = 'I hate this post!';
    $where .= " AND $wpdb->posts.post_title != '$title' ";
    return $where;
    }

    add_filter('posts_where', 'strike_title');

    Note here the add_filter(), which flips our SQL query fragment onto the posts_where API hook.

  3. aloncarmel
    Member
    Posted 7 years ago #

    It works! Your a genius.

    Can i use the posts.post_title for example examining the post_content ?

  4. aloncarmel
    Member
    Posted 7 years ago #

    Also, How can i return a value from an enum?

    Lets say i want to see if the post comment is 'spam' or not.
    when i tried

    $commentstatus = 'spam'

    $where .= " AND $wpdb->comments.comment_approved != '$commentstatus' ";

    it gives me an sql error, is the enum value should be read diffrently?

  5. Kafkaesqui

    Posted 7 years ago #

    "Can i use the posts.post_title for example examining the post_content ?"

    I guess you could. If you are working on individual post objects though, you'd be better off scoping $post to global and accessing a post's content like so:

    $post->post_content

    "Also, How can i return a value from an enum?"

    Note that 'posts_where' is the plugin API hook for the WHERE clause of the *posts* table query. I'm not aware of a similar hook for comments.

  6. aloncarmel
    Member
    Posted 7 years ago #

    Im not tryin to pull the data from the comment, I just gave an example.

    I save data for each post on an external table.

    I use the $wpdb.metainfo.priority != 'p1'; for example and it does not work because the field is enum and not text. How can i select that field? i saw that i need to select the post_id first and then the priority or somethin like that?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.