So here is shortcode that i can use to output names based on attributes.
For example, [my_site dfd_name="boy"]
will output all boys name.
However if I put “girl” in the name attribute, it does not recognize it. ([my_site dfd_name="boy,girl"]
).
Here is the full php:
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
function sp_shortcode_listings($atts, $content = null, $code = "") {
global $wp_query;
global $title;
global $active_tab;
global $showposts;
global $sp_taxonomy;
$defaults = array(
'type' => 'grid',
'before' => '',
'after' => '',
'wrap' => 'div',
'title' => '',
'showposts' => '12',
'type'=> 'grid',
);
extract( shortcode_atts( $defaults, $atts ) );
if ($showposts == 12) {
$showposts = isset($_GET['showposts']) ? $_GET['showposts'] : '12';
}
$shorcode = "sc";
if(!empty($atts))
{
foreach ( $atts as $key => $val)
{
if(strstr($key, 'dfd'))
{
$metaquery[] = array(
'key' => $key,
'value' => $val,
'compare' => 'LIKE',
'terms' => explode(',',$val)
);
}
}
}
if(empty($metaquery))
{
$shorcode = "";
}
global $active_tab;
$active_tab = isset( $_GET[ 'type' ] ) ? $_GET[ 'type' ] : $type;
include(my_site_dir . '/archive-filter.php');
global $post;
ob_start();
if ( have_posts() )
{
my_template_property_archive_content_main_shortcode();
}
else
{
echo apply_filters( 'my_site_no_match', 'Sorry, no name matched your criteria' ) ;
}
$output_string = ob_get_contents();
ob_end_clean();
$output = sprintf( '<%4$s class="sp">%1$s%3$s%2$s</%4$s>', $before, $after, $output_string, $wrap );
wp_reset_query();
return $output;
}
add_shortcode("my-listings", "sp_shortcode_listings");
?>
How can I change it so that I can add multiple values in the “dfd” attributes?
Thanks