0

I'm looking for help with a problem I've run into and can't seem to workout myself. I have created my own custom taxonomy called series (code below). I am calling the custom taxonomy posts in a widget using a plugin called "Flexible Posts Widget" (screenshot for widget below and code for plugin below).

This works fine and it calls the posts. But I want to create a "View All" link that goes to whatever "Series" (my custom taxonomy) that is being called within the widget. I tried the permalink but it goes to the last post being called and not to a page that lists all the posts under the taxonomy currently being called in that widget. I'm looking for a way to link to that page and make it dynamic as the custom taxonomy "Series" will change depending which series is being called in the widget.

Guidance is greatly appreciated - I will be very responsive!

functions.php / Where I register the taxonomy

function create_series_hierarchical_taxonomy() {
    $labels = array(
        'name'              => _x( 'series', 'taxonomy general name' ),
        'singular_name'     => _x( 'series', 'taxonomy singular name' ),
        'search_items'      => __( 'search series' ),
        'all_items'         => __( 'all series' ),
        'parent_item'       => __( 'parent series' ),
        'parent_item_colon' => __( 'parent series:' ),
        'edit_item'         => __( 'edit series' ),
        'update_item'       => __( 'update series' ),
        'add_new_item'      => __( 'add new series' ),
        'new_item_name'     => __( 'new series name' ),
        'menu_name'         => __( 'series' ),
    );

    $args = array(
        'hierarchical'      => true,
        'labels'            => $labels,
        'show_ui'           => true,
        'show_admin_column' => true,
        'query_var'         => true,
        'rewrite'           => array( 'slug' => 'series' ),
        'show_in_rest'      => true,
    );

    register_taxonomy('series', array('post'), $args );
}

The Flexible Posts Widget Code Template I edited to call my posts

// 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() ):
    ?>

    <div>
    <?php
    // This sets out a variable called $term - we'll use it ALOT for what we're about to do.
    $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?>
    <?php while( $flexible_posts->have_posts() ) : $flexible_posts->the_post(); global $post; ?>

        <h2><?php echo $term->name; ?></h2><!-- Prints the term name as set in the Widget -->

        <a href="<?php the_permalink(); ?>"><p><?php the_title();?></p></a>

    <?php endwhile; ?>
    </div>

    <a href="<?php the_permalink(); ?>">View All</a> <!-- This doesn't link to the current "Series" taxonomy page like I want it to -->

<?php else: // No Posts ?>
    <div class="dpe-flexible-posts no-posts">
        <p><?php _e( 'Empty', 'flexible-posts-widget' ); ?></p>
    </div>
<?php
endif; // End have_posts()

echo $after_widget;

Widget Screenshot For Visual Reference If It Helps

enter image description here

UPDATE

The answer provided by @bdtheme returns this error message, still looking for solution:

( ! ) Catchable fatal error: Object of class WP_Error could not be converted to string in C:..\wordpress\wp-content\plugins\flexible-posts-widget\views\series-template.php on line 46

Call Stack #TimeMemoryFunctionLocation 10.0005240784{main}( )...\index.php:0 20.0008243888require( 'C:..\wordpress\wp-blog-header.php' )...\index.php:17

30.717639617200require_once( 'C:..\wordpress\wp-includes\template-loader.php' )...\wp-blog-header.php:19 40.721039663800include( 'C:..\wordpress\wp-content\themes\hf\front-page.php' )...\template-loader.php:74 50.892539948680dynamic_sidebar( )...\front-page.php:95 60.894139952688 call_user_func_array:{C:..\wordpress\wp-includes\widgets.php:743} ( )...\widgets.php : 743 70.894139953272WP_Widget->display_callback( )...\widgets.php : 743 80.894339963256Flexible_Posts_Widget->widget( )...\class-wp-widget.php : 372 90.902740010816include( 'C:..\wordpress\wp-content\plugins\flexible-posts-widget\views\series-template.php' )...\class-fpw-widget.php : 197

0

Replace the line

<a href="<?php the_permalink(); ?>">View All</a>

with

<a href="<?php echo get_term_link($term,'series'); ?>">View All</a>

Reference: Codex Page

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.