WordPress.org

Ready to get started?Download WordPress

Forums

WP Document Revisions
[resolved] Wp doc rev: How to query properly (6 posts)

  1. toimisto
    Member
    Posted 2 years ago #

    Thanks for the BRILLIANT plugin. I'm struggling with query at the moment and wondered if someone here knows answer. I have a following query but I'd need to get UL tags inside if statement (and some other stuff). Any idea? Normal 'if while' structure leads to errors

    <ul>
    <?php
    global $post;
    $args = array( 'numberposts' => 500, 'orderby' => 'date', 'year' => '2012', 'order' => 'ASC', 'document_language' => 'english');
    $myposts = get_documents( $args );
    foreach( $myposts as $post ) :	setup_postdata($post); ?>
    	<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>
    </ul>

    http://wordpress.org/extend/plugins/wp-document-revisions/

  2. Ben Balter
    Member
    Plugin Author

    Posted 2 years ago #

    Can you write out (in psuedo-code if need be) what you're trying to do?

    Because documents are just posts, you should be able to query it normally, such as using wp_query or get_posts, if need be.

  3. toimisto
    Member
    Posted 2 years ago #

    <?php
    global $post;
    $args = array( 'numberposts' => 500, 'orderby' => 'date', 'year' => '2012', 'order' => 'ASC', 'document_language' => 'english');
    $myposts = get_documents( $args );
    <strong>
    if ( $myposts->have_posts() ) : $myposts->the_post(); { ?>
    <h1>Year 2012</h1>
    <? } while ( $myposts->have_posts() ) : $myposts->the_post(); ?>
    <strong>
    foreach( $myposts as $post ) :	setup_postdata($post); ?>
    	<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>
    <?php endwhile; endif; ?>

    I need to create a page with yearly archives and I thought it would be quickest just to query every year there manually. Problem is that I'd need few future years there also but I dont want these titles show up before there is documents for that year

  4. toimisto
    Member
    Posted 2 years ago #

    nevermind that < strong > there just tried to highlight that part... without thinking too much obviously

  5. Ben Balter
    Member
    Plugin Author

    Posted 2 years ago #

    Ahh, I see. If you change get_documents to WP_Query, and add 'post_type' => 'document' to the $args array, the above code should work as expected, I believe. get_documents behaves like get_posts, not WP_Query (returning an array versus a query object which you can iterate through like you are above).

  6. toimisto
    Member
    Posted 2 years ago #

    brilliant so simple! THANK YOU!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic