Forums

Fetch attachment from database, but only if post_content = word (4 posts)

  1. duenorth
    Member
    Posted 2 years ago #

    Hey everyone.
    Got stuck on this little thing today.
    I want to pull all attachments that are pictures with a description of logo into a select element.
    It just ignores the 'post_content' => 'Logo', part.

    $args = array(
    'post_type' => 'attachment',
    'numberposts' => -1,
    'post_content' => 'Logo',
    'post_mime_type' => array('image/gif','image/png','image/jpg','image/jpeg'),
    'post_status' => null,
    'post_parent' => null, // any parent
    );
  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    There isn't a post_content query parameter as far as I'm aware.

  3. Mark / t31os
    Moderator
    Posted 2 years ago #

    That's because post_content is not a valid query parameter.. (like esmi said as i was writing this reply)..

    The only way i can think of to query based on post_content would be to write your own query using one of the $wpdb methods.
    http://codex.wordpress.org/Function_Reference/wpdb_Class

  4. duenorth
    Member
    Posted 2 years ago #

    Thanks guys. Just fixed it with a custom $wpbd query.
    Looked like this for anyone wondering.

    $logo = $wpdb->get_results("SELECT id,post_content,guid
    	FROM <code>wp_posts</code>
    	WHERE post_mime_type
    	IN ('image/png','image/jpeg','image/gif')
    	AND post_content =  'logo'
    	AND post_type= 'attachment'");

Topic Closed

This topic has been closed to new replies.

About this Topic