Soliloquy Documentation

Documentation, Reference Materials, and Tutorials for Soliloquy

Featured Content: Custom Field Queries

Would you like to white label Soliloquy? You can easily do this by installing a custom plugin on your site! Simply create a plugin file to change all instances of “Soliloquy” to simply say “Slider” and remove the Soliloquy banner and branding.

Note: This tutorial is a bit more technical than our other docs, but we’ll walk you through the process step by step. In order to create the custom query for the Featured Content slider, we’ll need to create and upload a basic WordPress plugin.


Creating the Plugin

To create this custom query filter, just add the following code to a new file at wp-content/plugins/soliloquy-featured-content-custom-filter.php.

<?php
/**
* Plugin Name: Soliloquy - Featured Content - Custom Queries - Author
* Plugin URI: https://soliloquywp.com
* Version: 1.0
* Author: Soliloquy Team
* Author URI: https://soliloquywp.com
* Description: Restrict Featured Content by Author
*/

/**
* Add Author Arguments to Featured Content Queries
*
* @param string $html HTML Link
* @param obj $post WP_Post
* @param array $data Slider Configuration
* @return string HTML Link
*/
function sol_soliloquy_fc_custom_author( $query_args, $id, $data ) {

	// You could check for a specific slider slug here, if you only want
	// to amend your FC query on a single slider.
	if ( $data['config']['slug'] != 'my-slug' ){
		return $query_args;
 	}
	// $query_args is an array for WP_Query:
	// http://codex.wordpress.org/Class_Reference/WP_Query
	$query_args['author__in'] = array( 1, 2 ); // Only get Posts that belong to User IDs 1 or 2

	// Return query arguments
	return $query_args;

}
add_filter( 'soliloquy_fc_query_args', 'sol_soliloquy_fc_custom_author', 10, 3 );

If you’re unsure how to create a plugin file, follow these steps below:

  1. Open a text file and make sure that it is a plain text document. You can use a plain text editor like Notepad or a code editor of your choice.
  2. Next, copy and paste the code shown above into the file and save the file as soliloquy-featured-content-custom-filter.php
  3. Once you’ve saved the file you can easily upload this directly to your /plugins directory on your server using FTP or you can right-click on the text document and zip (or compress).
  4. Finally, log in to your WordPress dashboard and go to Plugins » Add New » Upload Plugin and upload the .zip file you just created in the previous step.

Note: It’s important to make sure you’ve set your slider slug name inside the plugin on line 23. Just replace the 'my-slug' with the slug name of your slider. You’ll also need to change the ID for the author on line 28 for the array( 1, 2 ); to match the ID of the author(s) you want to include.

Activate the Plugin

Your next step is to activate the plugin you just uploaded. Simply navigate to the Plugins from within your WordPress dashboard and activate the Soliloquy – Featured Content – Custom Queries – Author plugin.

Activate the plugin to begin filtering by author

That’s it! You’ve successfully filtered your Featured Content slides by Author!

Would you like to customize Soliloquy further? Have a look at our tutorial on How to Set a Default Caption.


FAQs

Are there other filters I can create?

A: Absolutely! This array of parameters is formatted for WP_Query. You can review their documentation on any other filters you would like. Below is an example of using Custom Fields for your query.

<?php
/**
* Plugin Name: Soliloquy - Featured Content - Custom Queries - Custom Fields
* Plugin URI: https://soliloquywp.com
* Version: 1.0
* Author: Tim Carr
* Author URI: http://www.n7studios.co.uk
* Description: Restrict Featured Content by Author
*/

/**
* Add Custom Field Arguments to Featured Content Queries
*
* @param string $html HTML Link
* @param obj $post WP_Post
* @param array $data Slider Configuration
* @return string HTML Link
*/
function sol_soliloquy_fc_custom_fields( $query_args, $id, $data ) {

	// You could check for a specific slider ID here, if you only want
	// to amend your FC query on a single slider.
	if ( 29 == $id ) {
		return $query_args;
	}

	// $query_args is an array for WP_Query:
	// http://codex.wordpress.org/Class_Reference/WP_Query

	// Check if Featured Content has already set some Custom Field arguments
	// If not, set the meta (custom field) query as an array
	// This prevents us overwriting any existing arguments that may exist
	if ( ! is_array( $query_args['meta_query'] ) ) {
		$query_args['meta_query'] = array();
	}

	// Only get Posts that have a custom field name of 'test' equal to a value of '1'
	// See https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters for full parameters
	$query_args['meta_query'][] = array(
		'key' 	=> 'test',
		'value' => '1',
	);

	// Return query arguments
	return $query_args;

}
add_filter( 'soliloquy_fc_query_args', 'sol_soliloquy_fc_custom_fields', 10, 3 );

Just remember to change the if ( 29 == $id ) { to match the ID of the slider you’re wanting to use this for.


Why isn’t my slider updating?

A: This could be a caching issue. You can edit the page and click Update to flush out the cache.