• Resolved prettynerd

    (@prettynerd)


    i would like to retrieve a post (an attachment, to be particular) with a description equal to my choosing..

    i have this code:

    query_posts(‘post_type=attachment&meta_key=post_content&meta_value=customAdLeft’);

    but it’s not working.. i do think this is invalid code.. =)

    please help.. thanks!

Viewing 1 replies (of 1 total)
  • Thread Starter prettynerd

    (@prettynerd)

    i found the solution myself! ehe..

    <?php

    $keyword = “keyword”;
    $args = array(
    ‘post_type’ => ‘attachment’,
    ‘numberposts’ => -1,
    ‘post_status’ => null,
    ‘post_parent’ => null, // any parent
    );
    $attachments = get_posts($args);
    if ($attachments) {
    foreach ($attachments as $post) {
    if(trim($post->post_content)==$keyword){
    setup_postdata($post);
    the_attachment_link($post->ID, false);
    }
    }
    }

    ?>

    if someone can help me make this shorter, please do.. =)

Viewing 1 replies (of 1 total)
  • The topic ‘how to get/query posts given a post_content’ is closed to new replies.