Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter ubertam

    (@ubertam)

    I ended up using Flexible Posts Widget instead, and making a custom plugin to let me change the sort.

    FPW lets you create a custom template (I called mine PCVA FPW Case Result, then added the file pcva_fpw_case_result.php to my child theme at \Jupiter-child\flexible-posts-widget\pcva_fpw_case_result.php). That PHP file declares the layout of the result so I can have minimal information, make it link where I want it to, etc. Here is that code:

    <?php
    /**
     * Flexible Posts Widget: Default widget template
     * 
     * @since 3.4.0
     *
     * This template was added to overcome some often-requested changes
     * to the old default template (widget.php).
     */
    
    // Block direct requests
    if ( !defined('ABSPATH') )
    	die('-1');
    
    echo $before_widget;
    
    if ( ! empty( $title ) )
    	echo $before_title . $title . $after_title;
    
    if ( $flexible_posts->have_posts() ):
    ?>
    	<ul class="dpe-flexible-posts custom-field-case_result_list_entry pcva_fpw_attyresult">
    	<?php while ( $flexible_posts->have_posts() ) : $flexible_posts->the_post(); global $post; ?>
    		<li id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    			<a href="<?php echo the_permalink(); ?>">
    				<?php the_field('case_result_list_entry'); ?>
    			</a>
    		</li>
    	<?php endwhile; ?>
    	</ul><!-- .dpe-flexible-posts -->
    <?php	
    endif; // End have_posts()
    	
    echo $after_widget;

    Then, I made the following custom plugin so they would be sorted my way. Note: this didn’t make the FPW widget interface give me those options; it just overrode whatever setting was there. Here’s that plugin code:

    <?php
    /* Adjust Flexible Posts Widget to order by meta_key */
    
    add_filter( 'dpe_fpw_args', 'pcva_fpw_sortmeta' );
    
    function pcva_fpw_sortmeta($query) {
    	$query['meta_key'] = 'hidden_sort_value';
    	$query['orderby'] = 'meta_value_num';
    	return $query;
    	
    }

    FPW already does custom taxonomies, so it had less to tweak to get this to work.

    Good luck!

    Thread Starter ubertam

    (@ubertam)

    If done correctly, it will override whatever the widget setting is set to. My guess is the code I added above isn’t being recognized. Couple possibilities:

    Is your code properly done in a custom plugin or in your theme’s functions.php file?
    If it is a custom plugin, is that plugin enabled?
    If sorting by text rather than numbers, change ‘meta_value_num’ to ‘meta_value’ – that might just be it.
    Make sure you replace ‘hidden_sort_value’ with your proper custom field.

    Thread Starter ubertam

    (@ubertam)

    Supporting custom taxonomies would be extremely awesome, as well. I have taxonomies for Case Results called “CR Attorneys” and “CR Practice Areas” so I don’t clutter up my “Categories” default taxonomy.

    I’d be willing to donate $100 to make this happen.

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