LoopBuddy Query/Hooks

LoopBuddy Query Overview

The LoopBuddy Query is where you create Queries, which in turn create and produce the Loops you want in WordPress. From showing certain posts to the number of posts, categories, posts with specific meta values and more, the LoopBuddy Query area is where you specify exactly what should be shown, and exactly what should not be shown, in a LoopBuddy output.

Advanced Meta Queries

With LoopBuddy 1.2, LoopBuddy Queries now allow you to perform some very powerful advanced Meta queries. Here is a video explaining and giving some examples of the advanced meta queries:

MISSING VIDEO

Advanced Taxonomy Queries

With LoopBuddy 1.2, LoopBuddy Queries now allow you to perform some very powerful advanced Taxonomy queries. Here is a video explaining and giving some examples of the advanced Taxonomy queries:

MISSING VIDEO

Hooks Overview

LoopBuddy allows you to create custom tags for the Layout editor. This is advanced functionality, so please don't attempt these steps if you are not intimately familiar with PHP and how LoopBuddy operates.

Creating a New Custom Tag

<?php
add_filter( 'pb_loopbuddy_custom_tags', 'my_custom_tag_add' );
function my_custom_tag_add( $custom_tags ) {
	//Always return $custom_tags
	$custom_tags[ 'start_wrap' ] = array( 
		'My Tag Label',
		array(
			'wrap' => 'div',
			'custom_class' => 'default class'
		)
	);
	return $custom_tags;	
} //end my_custom_tag_add

//Start off with the tag name, give the tag a label, and pass it which items it supports (all should ideally contain the 'wrap' and 'custom_class' items
?>

Here are some built in tag items that you can choose from:

  • link_text
  • custom_url
  • custom_class
  • link_title
  • before_text
  • after_text
  • meta_key
  • max_width
  • max_height
  • shortcode
  • author_link_destination
  • user_profile
  • permalink
  • attachment_link_display
  • separator
  • text
  • date_format
  • comment_number_zero
  • comment_number_one
  • comment_number_more
  • post_date
  • bloginfo
  • content_more
  • url_display
  • image_size

Creating a New Custom Tag Item

<?php
add_filter( 'pb_loopbuddy_tag_items', 'my_custom_item_add' );
function my_custom_item_add( $loopbuddy_items ) {
	//Always return $loopbuddy_items
	
	$loopbuddy_items[ 'my_custom_item' ] = array( 
		'function' => 'callback_function',
		'args' => array(
			'label' => __( 'Link Text', 'LION' ),
			'tip' => __( 'Optional text for link.  Leave blank to use link as the text.', 'LION' ),
			'options' => array( 'option1', 'option2' )
		)
	);
	return $loopbuddy_items;
} //end my_custom_item_add

/* $settings are the arguments passed for the tag item and looks like this 
 [label] => HTML Wrapper
    [tip] => Choose which HTML element to wrap around the item
    [options] => Array
        (
            [0] => none
            [1] => span
            [2] => div
            [3] => p
            [4] => h1
            [5] => h2
            [6] => h3
            [7] => h4
            [8] => h5
            [9] => h6
        )

    [key] => wrap
    [settings] => Array
        (
            [image_size] => thumbnail
            [max_width] => 
            [max_height] => 
            [wrap] => p
            [before_text] => 
            [after_text] => 
            [custom_url] => 
            [custom_class] => attachment
            [tag] => wp_get_attachment_image
        )

)
*/
function callback_function( $settings ) {
	$defaults = array(
		'key' => '',
		'label' => '',
		'tip' => false,
		'settings' => array(),
		'options' => array()
	);
	extract( wp_parse_args( $settings, $defaults ) );
	//Output HTML for the item
} //end callback_function

?>

Callback Function for Displaying the Tag

<?php
/*$settings contains the tag items and the tag item's value
	Example
			Array
		(
		    [image_size] => thumbnail
		    [max_width] => 
		    [max_height] => 
		    [wrap] => p
		    [before_text] => 
		    [after_text] => 
		    [custom_url] => 
		    [custom_class] => attachment
		    [tag] => wp_get_attachment_image
		)
	*/
	
//Add header code
add_action( 'pb_loopbuddy_tag_header-mytagname', 'my_custom_tag_header' );
function my_custom_tag_header( $settings ) {
	echo "my header, notes, or other code";
	//Render your tag based on its settings
} //end my_custom_tag_header

//Add footer code
add_action( 'pb_loopbuddy_tag_footer-mytagname', 'my_custom_tag_footer' );
function my_custom_tag_footer( $settings ) {
	echo "my footer, notes, or other code";
	//Render your tag based on its settings
} //end my_custom_tag_header

add_filter( 'pb_loopbuddy_tag_supports-mytagname', 'my_custom_tag_supports' );
//Return an array of what tag items the tag supports
function my_custom_tag_supports( $support_tag_items ) {
	return array( 'wrap', 'link_text', 'before_text', 'after_text', 'custom_class' );
	//Render your tag based on its settings
} //end my_custom_tag_supports
?>

Rendering the Tag on the Front-end

<?php
add_filter( 'pb_loopbuddy_render-mytagname', 'mytagname_frontend', 10, 2 );
function mytagname_frontend( $post_object, $tag_items ) {
	/* $tag_items look like this
	(
    [wrap] => none
    [link_text] => Edit Post
    [before_text] => 
    [after_text] => 
    [custom_url] => 
    [custom_class] => 
    [tag] => edit_post_link
	)
	*/
	$return = false; //Populate the $return variable
	$return = pluginbuddy_loopbuddy_render_slotitems::get_output( $return, $post_object, $tag_items, true ); //The last argument is skip_before text 
	return $return;
} //end mytagname_frontend
?>

Ignoring Post Types in the Layout Editor

There will be certain post types that are public and have a public user interface, but the user would still not like to be able to configure override settings in the LoopBuddy Settings page.

A plugin author can use the following hook to remove these post types:

<?php
	add_filter( 'pb_loopbuddy_exclude_post_types', 'myplugin_exclude_post_types' );
	function myplugin_exclude_post_types( $post_types_to_exclude ) {
		$post_types_to_exclude[] = 'my_custom_post_type';
		return $post_types_to_exclude;
	}
?>

Have more questions? Submit a request