I’m using a custom wp-query on my website to display all pages from a parent page inside a list style with select, when selecting a page I’m redirected to the right page.

works fine :

here is my code :

<?php
            $args = array(
            'post_type'      => 'page',
            'posts_per_page' => -1,
            'post_parent'    => '22',
            'order'          => 'ASC',
            'orderby'=>'meta_value',
            'meta_key'=>'nom_de_loeuvre'
            );
            $parent = new WP_Query( $args );
            if ( $parent->have_posts() ) : ?>
            <span class="styled-select">
                <select name="" onchange="location = this.options[this.selectedIndex].value;">
                <option>A - Z</option>
                <?php while ( $parent->have_posts() ) : $parent->the_post(); ?>
                        <option value="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                        <?php the_field('nom_de_loeuvre'); ?>
                        , de 
                        <?php if(get_field('prenom_artiste')): ?>
                        <?php the_field('prenom_artiste'); ?>
                        <?php endif ;?>
                        <?php the_field('nom_artiste'); ?> | Galerie 
                        <?php if(get_field('prenom_galerie')): ?>
                        <?php the_field('prenom_galerie'); ?>
                        <?php endif ;?>
                        <?php the_field('nom_galerie'); ?>
                        </option>
                <?php endwhile; ?>
                </select>
            </span>
            <?php endif; wp_reset_query(); ?>

no I’m trying to hightlight the active page of my list, using “option selected value”.
when on a page, I want the select list to display the current page in the liste.
Can anybody help me with this ?

I can’t find a solution or a way to do it on the web…
I’m not sure if it’s possible, but I guess if it is, It must be something to add in my Wp-query or maybe in jquery ?

thanks a lot for your help…

Read more here: highlight active page option value in select element using "option selected value"


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , , , , , ,

Wordpress related questions and answers: