• Resolved sjteef

    (@sjteef)


    Hi,

    is there a way to assign post to the widget by giving it a costum variable? or to exclude using this method.

    Current situation

    <?php
    /**
     * Flexible Posts Widget: Default widget template
     */
    
    // 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">
    	<?php while( $flexible_posts->have_posts() ) : $flexible_posts->the_post(); global $post; ?>
    
    <hr>
    
    <span class="entry-date"><?php echo get_the_date(); ?></span>
    
    			<a href="<?php echo the_permalink(); ?>">
    					<?php the_title(); ?></h4>
    			</a>
    
    	<?php endwhile; ?>
    	</ul><!-- .dpe-flexible-posts -->
    <?php else: // We have no posts ?>
    	<div class="dpe-flexible-posts no-posts">
    		<p><?php _e( 'Geen actuele storingen', 'flexible-posts-widget' ); ?></p>
    	</div>
    <?php
    endif; // End have_posts()
    
    echo $after_widget;

    https://wordpress.org/plugins/flexible-posts-widget/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author DaveE

    (@dpe415)

    Hi sjteef,

    If I understand your question correctly, you’d like to be able to adjust what posts are returned based on a a custom post meta key/value? If that is the case, there is a filter available on the FPW query: dpe_fpw_args. You’d need to adjust the query variables to use custom meta values as parameters of the query.

    The code would look something like this (only an example):

    add_filter( 'dpe_fpw_args', 'fpw_custom_args' );
    function fpw_custom_args( $args ) {
    		$args['meta_key'] = 'my_custom_key';
    		$args['meta_value'] = 'my_custom_value';
    	}
    	return $args;
    }

    In the future, I’m planning to add another widget specifically for querying by custom meta values; but as it stands now, FPW doesn’t support this natively. You’ll have to use the filter and write the parameters yourself.

    Thanks for using the plugin!

    Plugin Author DaveE

    (@dpe415)

    Forgot to mention that you’d need to add this filter to your theme’s functions.php file. Cheers!

    Thread Starter sjteef

    (@sjteef)

    HI, Thanks for the fast responds.
    but i am not a coder. how can ik use the add filter?

    do i need to replace a specific line?

    Regards stefan from the netherlands.

    Plugin Author DaveE

    (@dpe415)

    Hi Stefan,

    Unfortunately, it isn’t really easy to explain without some knowledge of code. In your situation I’d recommend finding a developer who can help you or trying another plugin/option for your situation.

    Sorry I can’t be more help!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Exclude post using costum fields’ is closed to new replies.