Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • I could also use this feature. I just want to be able to feature content in a sidebar, regardless of whether it’s a page or a post. Certain features would obviously not be able to be taken advantage of (e.g. excerpts, sticky).

    Maybe just allow users to type in page id #’s similar to how exclusions and sticky posts are currently treated.

    It’d be especially great if it somehow could order the pages and the posts by date together instead of separate. Might be difficult since they’d be separate objects. Otherwise they could just be added to the end of the list.

    Thread Starter presspressperson

    (@presspressperson)

    Wooo! I figured it out. I found the following wonderfully wonderful solution: https://wordpress.stackexchange.com/questions/12133/using-posts-where-on-a-query-with-a-custom-field

    Basically, there is a way to add conditions to your $args (or $query_string) that deal with data from the wp_meta table. Here is what I ended up with.

    Before the loop:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $today = time();
    $args= array(
    'meta_query' => array(
    	array(
    	'key' => 'wpcf-event-end',
    	'value' => $today,
    	'compare' => '>='
    	)
    ),
    'category_name' => $cat_slug, // category slug (be sure to set $cat_slug above)
    'post_status' => 'publish',
    'paged' => $paged,
    'posts_per_page' => -1,
    'orderby' => 'date',
    'order' => 'ASC',
    );
    $query = new WP_Query( $args );

    The loop:

    <?php
    if( $query->have_posts() ) :
    
    twentyeleven_content_nav( 'nav-above' );
    
    while ( $query->have_posts() ) : $query->the_post();
    get_template_part( 'content', 'events' );
    endwhile;
    
    twentyeleven_content_nav( 'nav-below' );
    
    else :
    // Display a message and search form for if there are no events
    ?>

    Works like a charm! Thanks for the help Anne, and Stackexchange!

    Thread Starter presspressperson

    (@presspressperson)

    Thanks Anne. Quick reply!

    Great suggestion. Thanks. It took me a bit to figure out that I needed to change some of the code in my loop in order for new WP_Query() to work correctly. Otherwise it gets posts, but doesn’t display them for some reason. Namely:

    <?php
    if( have_posts() ) : // when using query_posts($args)
    if( $query->have_posts() // when using $query = new WP_Query($args)
    
    //same goes for the following
    while ( $query->have_posts() ) : $query->the_post();
    ?>

    I also found the exact database entry I need to compare in the filter function. I’m using the Types plugin to give my posts custom fields that users can input with the WordPress CMS, and then I display the input with my custom templates.

    Here is the problem. Types uses the wp_postmeta table. In the meta table, everything has a meta_key and a meta_value (both columns). So instead of simply adding $where .= “AND my_event_date > ‘” . date() . “‘”; as a filter, I somehow have to look for the meta_value of the row with meta_key equal to ‘wpcf-event-end’ (my event’s end date), and compare that to date() (the current unix timestamp).

    Unfortunately, sql is not my thing. If anyone can help it’d be greatly appreciated. Thanks in advance!

    I used css to hide topics with the following rule:

    tr.topic.status-pending { display:none; }

    You can do the same thing with posts, but unfortunately, the post header will remain since it’s a separate tr that doesn’t include the class “status-pending.”

    tr.reply.status-pending { display:none; }

    You could probably use ajax to grab the tr just before each tr.reply.status-pending and give it an inline style of display:none; but that is not my area of expertise.

    Also, your # of posts and topics will be incorrect (as in “Viewing 2 posts – 1 through 2 (of 2 total)“) unless you update the logic. I hide those too because I feel like they just add clutter to the page, and most of those numbers are already in the “notice” section. You can do that easily with css as well:

    div.bbp-pagination-count { display:none; }

    If your forum is paged your pages might end up being a few topics/replies short of the max per page, and you could end up with empty pages since the pagination is still counting the hidden topics/replies. Setting the topics/replies per page # to something high and staying on top of approval/deletion will minimize that.

    The method isn’t perfect, but it gets the job done quick and easy without any functionality issues.

    I’d be interested to hear a back end solution to this. In my humble opinion, showing pending topics almost defeats the purpose since you can still read the name of the topic.

Viewing 4 replies - 1 through 4 (of 4 total)