Forum Replies Created

Viewing 15 replies - 1 through 15 (of 18 total)
  • Thread Starter robpinney

    (@robpinney)

    I see. My understanding was that the ‘key’ listed in the array further down in the query replaced that – there are two possible values, hbk_publication_date and pbk_publication_date, so it had to be set this way.

    Is it not possible to use this same query model with ALM? I’m not sure how else I can build two meta_key queries into the original query.

    Thanks

    Thread Starter robpinney

    (@robpinney)

    Yes, very confused!

    Basically what I want to do is this: order by hbk_publication_date, or if it isn’t present, by hbk_publication_date and to show the ones closest to today first. They will all be in the future.

    Thread Starter robpinney

    (@robpinney)

    Thanks, that’s very nearly perfect. The only problem I’m having is that it isn’ replicating the same order as the query I pasted above – that loop shows 8 items, so I’m using an offset value of 8 in order to follow on from there. The issue is that it’s not offsetting the same 8 items. I’ve tried changing the meta_type value and also playing with the order, but with no luck.

    Thread Starter robpinney

    (@robpinney)

    Thanks, that’s fixed the error problem perfectly. Now I need to try and set up this rather complicated query – basically the items I’m loading have a custom field (a date), and I want to only show items for which the date is equal to today or in the future.

    The original query for the loop looks like this:

    <?php 
    
    // args
    $today = date("Ymd");
    
        $args = array (
                'post_type' => 'book',
                'cat'  => $cat,
                'showposts' => '8',
                'orderby'       => 'meta_value_num',
                'order'          => 'DESC',
       'meta_query' => array(
           'relation' => 'OR',
             array(
                'key'       => 'hbk_publication_date',
                'compare'   => '>=',
                'value'     => $today,
            ),
           array(
                'key'       => 'pbk_publication_date',
                'compare'   => '>=',
                'value'     => $today,
            ),
        ),
    );
    
    // get results
    $the_query = new WP_Query( $args );
    
    // The Loop
    ?>

    I then want ALM to show further posts based on that query. Is that doable?

    Thanks for your help.

    Thread Starter robpinney

    (@robpinney)

    @girlieworks: Thanks again!

    Thread Starter robpinney

    (@robpinney)

    @girlieworks: Yes, that fixes the problem! Thank you so much for all your help.

    Thread Starter robpinney

    (@robpinney)

    @girlieworks: I’m on 4.42 apparently.

    Thread Starter robpinney

    (@robpinney)

    @girlieworks: Ah, that makes a difference! I had two further child categories with higher IDs (for the issues to be published on 1st May and 1st June respectively), but with the posts saved only as drafts until it is time for them to go live. I just tried deleting those categories and suddenly it works.

    So: it seems that the query is now also taking into account child categories without published posts, whereas before it would disregard these. Is there a way to get it to only look for categories with posts published within them?

    If not I can work around this, but it’d be great to have it running exactly as before again.

    Thanks

    Thread Starter robpinney

    (@robpinney)

    @girlieworks: OK so with both pieces of code (the original and the one you suggested), it pulls in the category description for the first category that was added if order is set to ASC. When I change it to DESC, I get the same two errors:

    Notice: Undefined offset: 0 in /nas/content/staging/criticalmuslim/wp-content/themes/wordpress-bootstrap-master/home.php on line 33

    Notice: Trying to get property of non-object in /nas/content/staging/criticalmuslim/wp-content/themes/wordpress-bootstrap-master/home.php on line 33

    In both cases it is still pulling in the first ten posts added to the site – these correspond to the lowest child category ID, but I think it’s likely that the category query isn’t working at all.

    Thread Starter robpinney

    (@robpinney)

    @girlieworks: Yes to both questions – category 3 has child categories, and there are published posts within them.

    Thread Starter robpinney

    (@robpinney)

    @girlieworks: I get the following errors with debug on:

    Notice: Undefined offset: 0 in /nas/content/staging/criticalmuslim/wp-content/themes/wordpress-bootstrap-master/home.php on line 33

    Notice: Trying to get property of non-object in /nas/content/staging/criticalmuslim/wp-content/themes/wordpress-bootstrap-master/home.php on line 33

    Line 33 is:

    <?php $issue = get_terms('category', 'orderby=ID&order=DESC&number=1&child_of=3'); $latest_issue = $issue[0]->term_taxonomy_id; ?>
    Thread Starter robpinney

    (@robpinney)

    @girlieworks: It isn’t pulling from a particular category at all, so $latest_issue is not working – apologies for not making that clearer. It should pull the category description and then all the posts in that category for the most recent child category (with the highest ID). Instead it is showing no category description and the oldest 10 posts.

    Find the full code pasted below – this works perfectly on the last version of WP, but not with 4.5.1.

    <?php $issue = get_terms('category', 'orderby=ID&order=DESC&number=1&child_of=3'); $latest_issue = $issue[0]->term_taxonomy_id; ?>
    
                        <section class="leader clearfix buffer">
                            <div class="home-content-header">
                                <h2>The Latest: <?php echo get_cat_name( $latest_issue );?></h2>
                            </div>
                            <section class="post_content home-excerpt clearfix"><?php echo category_description( $latest_issue ); ?></section>
                        </section>
    
                        <?php query_posts(array( 'category__in' => $latest_issue, 'orderby' => 'date',
    'order' => 'ASC' )); ?>
                        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
                        <article id="post-<?php the_ID(); ?>" <?php post_class('clearfix card'); ?> role="article">
    
    						<header class="home-header">
    
    							<a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail( 'wpbs-featured' ); ?></a>
    
    						</header> <!-- end article header -->
    
                            <section class="home-content clearfix">
    
                                <div class="home-content-header"><h1 class="h2"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a> <span><?php the_author_posts_link(); ?></span></h1></div>
    
    <time datetime="<?php echo the_time('Y-m-j'); ?>" pubdate></time>
    
                                <section class="post_content home-excerpt clearfix">
    							<?php the_excerpt(); ?>
    						</section>
    
    					</article> <!-- end article -->
    
    					<?php endwhile; ?>
    Thread Starter robpinney

    (@robpinney)

    @girlieworks: That’s right – it should pull the child category with the highest ID, and thus the most recent one, but it’s not working for me anymore.

    Thread Starter robpinney

    (@robpinney)

    It suddenly seems to be working again — perhaps just a temporary glitch. I’ll keep an eye on it. Thanks for your help.

    Thread Starter robpinney

    (@robpinney)

    The site isn’t public yet — can I email you some login details?

Viewing 15 replies - 1 through 15 (of 18 total)