Forum Replies Created

Viewing 6 replies - 1 through 6 (of 6 total)
  • @lonchbox

    Check my answer here: http://wordpress.org/support/topic/plugin-featured-page-widget-changing-the-order-of-pages?replies=2#post-3364016

    Find the bits in that file where it says 'orderby' => 'rand',, and change rand to some other supported value.

    adam.harvie

    (@adamharvie)

    I was able to change the order successfully, in featured-page-widget.php, starting at line 317:

    /* Get the list of pages */
              if ( $instance['category'] != -1 ) {
                   $pages = array_flip($this->options->post_types);
                   unset($pages['page']);
                   $this->options->post_types = array_flip($pages);
                   $args = array(
                        'category__in' => $instance['category'],
                        //'post__not_in' => array($post->ID),
                        'posts_per_page' => $instance['items'],
                        'order' => 'ASC',
                        'orderby' => 'menu_order',
                        'post_type' => $this->options->post_types,
                        'ignore_sticky_posts' => true,
                   );
              } else {
                   $args = array(
                        'post__in' => $instance['page'],
                        'posts_per_page' => $instance['items'],
                        'order' => 'ASC',
                        'orderby' => 'menu_order',
                        'post_type' => $this->options->post_types,
                        'ignore_sticky_posts' => true,
                   );
              }

    I’m using menu_order instead of title.

    Forgot to say, the other place I got some helpful tips was from this stackexchange thread.

    Ok I figured out a solution: It was key to move the modification of the main query out of the template (home.php) and into the function in functions.php with pre_get_posts. The other issue was solved by keeping the specific wp_query object to reference for the featured posts loop (which happens first in the template), and then using wp_reset_postdata():

    <?php
    	        	// customizing arguments for WP_Query - altering the query so that both 'event' and regular post types are supported
    	        	$featured_args = array(
    	        		'post_type'=>array('post','event'),
    	        		'tax_query'=>array(	//pull from both event and regular post categories
    	        			'relation' => 'OR',
    	        			array(
    	        				'taxonomy' => 'event-categories',
    	        				'field' => 'id',
    	        				'terms' => of_get_option('home_feature_event'),
    	        			),
    	        			array(
    	        				'taxonomy' => 'category',
    	        				'field' => 'id',
    	        				'terms' => of_get_option('home_feature'),
    	        			),
    	        		),
    	        		'posts_per_page' => 1,
    	        	);
    	        ?>
    				<?php $wp_query = new WP_Query($featured_args);
    				?>
                    <?php if($wp_query->have_posts()) : while($wp_query->have_posts()) : $wp_query->the_post(); ?>
                    <?php $meta_box = get_post_custom($post->ID); $video = $meta_box['custom_meta_video'][0]; ?>
                    <?php global $more; $more = 0; ?>
    
                        <?php if ( $video ) : ?>
                            <div class="feature_video"><?php echo $video; ?></div>
                        <?php else: ?>
                            <a class="feature_img" href="<?php the_permalink() ?>" rel="bookmark"><?php the_post_thumbnail( 'home-feature' ); ?></a>
    
                        <?php endif; ?>
    
                        <div class="feature_info">
                            <h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    
                        </div>
    
                    <?php endwhile; wp_reset_postdata(); ?>

    Then for the main loop, since the query modification was moved to functions.php, the specific wp_query object that was previously being used had to be removed, to make sure it’s referencing the ‘main’ (global) object:

    <?php if(have_posts()) : while(have_posts()) : the_post(); ?>

    Previously the query modification had all been in home.php, so that had been $wp_query->have_posts(), etc. Taking the query modification out and moving it in to functions.php meant there wasn’t a $wp_query = new WP_Query() for the second loop, and the loop being referenced was the previous Featured posts one. Not being super familiar with WP yet, I didn’t realize I could just take the object reference out to get the ‘main’ query.

    Many thanks to keesiemeijer. Your first bit of code and the link you provided put me on the right track.

    Ah, ok, thanks. That fixes the pagination 404s, though there’s another issue: the theme has a ‘featured’ posts area preceding the main paginated post list. It sets up the query for that in largely the same way:

    <?php
    	        	// customizing arguments for WP_Query - altering the query so that both 'event' and regular post types are supported
    	        	$featured_args = array(
    	        		'post_type'=>array('post','event'),
    	        		'tax_query'=>array(	//pull from both event and regular post categories
    	        			'relation' => 'OR',
    	        			array(
    	        				'taxonomy' => 'event-categories',
    	        				'field' => 'id',
    	        				'terms' => of_get_option('home_feature_event'),
    	        			),
    	        			array(
    	        				'taxonomy' => 'category',
    	        				'field' => 'id',
    	        				'terms' => of_get_option('home_feature'),
    	        			),
    	        		),
    	        		'posts_per_page' => 1,
    	        	);
    	        ?>
    				<?php $wp_query = new WP_Query($featured_args); ?>
                    <?php if($wp_query->have_posts()) : while($wp_query->have_posts()) : $wp_query->the_post(); ?>

    If this first query is still present, then the main paginated one seems to share the query results, since I’m no longer doing new WP_Query($home_args); before the main query. Is there a way to set this up so that the first query doesn’t get carried over?

    I tried deactivating the plugin, and all the Order fields disappear. I’ve also noticed that when quick editing an event in EM, four Order fields appear.

    I’ve actually installed it specifically for ordering event categories. It doesn’t seem to affect anything adversly, just thought I might give a heads up.

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