Soliloquy Documentation

Documentation, Reference Materials, and Tutorials for Soliloquy

Featured Content: Exclude Current Post from Sliders

Important: This doc assumes you’re comfortable creating and/or editing PHP files in your WordPress installation and is intended for advanced users.

Note: This document is relevant only if you have a Developer or Master license and you’re using the Featured Content Addon.

If you’re embedding a Soliloquy slider into a Post that would otherwise be included in a Featured Content slider, you can exclude the current displayed Post from the slider following this guide.

Step 1 – Create Plugin File

The first step is to create a new php file in the wp-content/plugins/ directory of your WordPress installation. The easiest way to do this is using your favorite FTP program or through your web hosting account’s file editor (if they provide one).

Once you’ve navigated to the wp-content/plugins/ directory, create a new file with the name soliloquy-featured-content-exclude-current-post.php

Step 2 – Edit the New Plugin File

Next, you’ll want to copy and paste the following code into the soliloquy-featured-content-exclude-current-post.php plugin file you’ve created:

<?php
/**
* Plugin Name: Soliloquy - Featured Content - Exclude Current Post
* Plugin URI: https://soliloquywp.com
* Version: 1.0
* Author: Tim Carr
* Author URI: http://www.n7studios.co.uk
* Description: Excludes the current singular Post, Page or CPT from the Featured Content Slider
*/

/**
* Start the slider based on the supplied index
*
* @param array $data Slider Data
* @param int $sliderID Slider ID
* @return array Slider Data
*/
function sol_soliloquy_fc_exclude_current_post( $query_args, $id, $data ) {

	global $post;

	// Check if we're on a singular post
	if ( ! is_singular() || ! is_main_query() ) {
		return $query_args;
	}
	
	// Define post__not_in, if we haven't excluded any Posts yet
	if ( ! isset( $query_args['post__not_in'] ) ) {
		$query_args['post__not_in'] = array();
	}

	// Exclude the current Post
	$query_args['post__not_in'][] = $post->ID;
	var_dump($query_args);

	// Return
	return $query_args;
	
}
add_filter( 'soliloquy_fc_query_args', 'sol_soliloquy_fc_exclude_current_post', 10, 3 );

Step 3 – Activate the New Plugin

The last step is to navigate to the WordPress Admin > Plugins screen, locate the plugin named Soliloquy – Featured Content – Exclude Current Post and activate the plugin.

That’s it! You’ve successfully excluded the current post from populating your Featured Content sliders!


Troubleshooting

  • Be sure you’re running Soliloquy 2.x or higher
  • Be sure you’re running Soliloquy Featured Content 2.x or higher
[i]
[i]