• Hi,
    there is possible to show only the posts without a certain custom field?

    For example, I have two posts with this custom_field:

    1-Post (my_c_field = true)
    2-Post
    3-Post
    4-Post (my_c_field = true)
    5-post

    I’d like to show only
    2-Post
    3-Post
    5-Post

    There is possible?
    Please, help me ??

Viewing 12 replies - 1 through 12 (of 12 total)
  • I think you’ll need a plugin or a custom template to do that…

    Don’t know how current this is but look at
    Displaying_Posts_Using_a_Custom_Select_Query

    So… you want to write posts but not ever show them? That’s odd, isn’t it?

    Or do you just want to not show them on the front page? If so, why not put them in a special category and then use one of the several “Category Visibility” plugins to keep ’em off the front?

    Thread Starter pennywise83

    (@pennywise83)

    I’d want to have a sticky posts. I’ve tried the wp-sticky and adhesive one but it doesn’t make what I’m looking for because they show the sticky post on the top of the loop.

    I want to have an index.php page that look’s like this:

    // STICKY
    3- post (sticky)
    5- post (sticky)
    //

    // THE OTHER POSTS (doesn’t show the post’s with the “sticky” custom field set to “true”

    1- post
    2- post
    4- post
    6- post

    I want to use the custom fields and not the categories…

    Well, if the numbers indicate a chronological order (in which the posts were created) WP will rather display:
    6
    4
    2
    1

    Thread Starter pennywise83

    (@pennywise83)

    rudolf45: ???

    Oh, that was just a side note about the post order…

    Back to your question: I don’t see what is the difference between having the sticky “on the top of the loop” (your words) and the order you presented above? Aren’t the stickies above the rest of the posts?

    Thread Starter pennywise83

    (@pennywise83)

    Exactly.
    I would have two boxes, the first one with the sticky posts and after another one with the rest of the posts

    /////////////////
    STICK YPOSTS
    3- post (sticky)
    5- post (sticky)
    ////////////////

    ////////////////
    OTHER PSTS
    1- post
    2- post
    4- post
    6- post
    ////////////////

    I think I am getting now what you want: you want the sticky posts to be styled (designed) in a different way, right?

    I think Gamerz’s Sticky plugin has an “if is_sticky” function that might be used to do what you want. Just a thought…

    Thread Starter pennywise83

    (@pennywise83)

    Yes, I’d like to style the sticky posts in a different way from the loop, but I want also that the sticky posts doesn’t appears in the loop… do you think that with gamerz wp-sticky is it possible ?

    You seem to be obsessed by the Loop thing. There is NO posts outside the Loop. Without the Loop you see nothing.

    So, let’s start from here.

    Thread Starter pennywise83

    (@pennywise83)

    Ok… there was a misunderstanding by my for the “loop” term, so I have this code in index.php to show the posts:

    <?php if (have_posts()) : ?>
    
    	<?php while (have_posts()) : the_post(); ?>
    
    // Print post title, post author, etc.
    
    	<?php endwhile; ?>
    <?php endif; ?>

    And this one that fetch only the posts with my custom field tag:

    <?php $pageposts = $wpdb->get_results("SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
        WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = 'my_custom_field' AND wpostmeta.meta_value = 'true' AND
        wposts.post_status = 'publish' AND wposts.post_date < NOW() ORDER BY wposts.post_date DESC", OBJECT); ?>
    <?php if ($pageposts): ?>
     <?php foreach ($pageposts as $post): ?>
     <?php setup_postdata($post); ?>
    <?php endforeach; ?>
     <?php endif; ?>
    // Print post title, post author, etc.

    This is, almost, the code and both works, i would like to have the first query excludes the posts with “my_custom_field” = “true”.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Exclude a custom field inside the loop when showing posts’ is closed to new replies.