Change wp_query on the detail pages of each project according to the selected option on the project page

Asked

Viewed 23 times

0

On the project page, where all the projects are, you have one option(select option) to sort alphabetically and another to sort chronologically. When going to the detail of each project has a link to the following project and another link to the previous one. I wanted to ask if it is possible the previous and next project are sorted according to the selected option of the project page.

Project page: http://alvarovarejao.com/designpublico/pt/projetos/

    <div class="row filterr">
<div class="filter">
    <input type="radio" name="ccc" class="alfabet" id="c1" value="1">
        <label for="c1">
            <?php 
                if (get_locale() == 'en_US') { echo " Alphabetical"; } else { echo " Alfabeticamente"; }
            ?>
        </label>
        <br>
    <input style="margin-top: 12px;" type="radio" name="ccc" id="c2" value="2">
        <label for="c2">
            <?php 
                if (get_locale() == 'en_US') { echo " Chronological"; } else { echo " Cronologicamente";} ?> 
        </label>
        <br>
    <input style="visibility: hidden;" type="radio" name="ccc" id="c3" value="3" checked="checked">
        <label for="c3" style="visibility: hidden;">
        <?php 
                if (get_locale() == 'en_US') { echo " Random"; } else { echo " Aleatoriamente";} 
        ?>
        </label>
</div>
</div>



<div class="text">

<div id="primary" class="row projects projects-filter">

        <?php

        if(substr($_SERVER['REMOTE_ADDR'], 0, 4) == '127.' || $_SERVER['REMOTE_ADDR'] == '::1') {
            if (get_locale() == 'en_US') { $project = 47; } else { $project = 49; }
        } else {
            if (get_locale() == 'en_US') { $project = 69; } else { $project = 71; }
        }


    $query = new WP_Query( array( 'post_type' => 'post','orderby' => 'rand',
    'order' => 'ASC', 'cat' => $project ) );

    if ( $query->have_posts() ) :

        while ( $query->have_posts() ) : $query->the_post();

            get_template_part( 'template-parts/content', get_post_format() );

        endwhile; 
    else :
        endif;
        ?>

</div>
</div>

<div class="text2" style="display: none;">
    <div id="primary" class="row projects projects-filter">



        <?php
    $query = new WP_Query( array( 'post_type' => 'post','orderby' => 'date',
    'order' => 'DESC', 'cat' => $project ) );

    if ( $query->have_posts() ) :

        while ( $query->have_posts() ) : $query->the_post();

            get_template_part( 'template-parts/content', get_post_format() );

        endwhile;
    else :
        endif;
        ?>

</div>
</div>

<div class="text3" style="display: none;">
    <div id="primary" class="row projects projects-filter">



        <?php
    $query = new WP_Query( array( 'post_type' => 'post','orderby' => 'title',
    'order' => 'ASC', 'cat' => $project ) );

    if ( $query->have_posts() ) :

        while ( $query->have_posts() ) : $query->the_post();


            get_template_part( 'template-parts/content', get_post_format() );

        endwhile;
    else :
        endif;
        ?>

</div>
</div>
  • Possible is, but it depends on how your queries are being done - mainly the reordering. Edit the question by placing the relevant code snippets.

  • I put the code where the ordering is done on the project page. The problem is to save the ordering so that it stays in the detail of each project.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.