How to display mysql query that ran in wp_query wordpress?

$args = array(
‘post_type’ => ‘auto’,
‘posts_per_page’ => -1,
‘meta_query’ => $meta_query
);

$mquery = new WP_Query($args);

echo $mquery->request;

$mquery->request will return the sql query formed.

 

Advertisements

wp_nav_menu() with custom html and dynamic class before each menu

This is my Menu Html format :


Code to display Menu in the page dynamically using the above html structure:

$menuParameters = array(
‘theme_location’ => ‘top’,
‘menu’ => ‘Top Menu’,
‘container’ => false,
‘echo’ => false,
‘items_wrap’ => ‘%3$s’,
‘link_before’ => ”,
‘link_after’ => ”,
‘depth’ => 0,
);
$menu = strip_tags(wp_nav_menu($menuParameters ), ‘<a><span>’ );
$find = array(‘<a’);
$replace = array(‘<a class=”list-group-item list-group-item-success” data-parent=”#MainMenu”‘);
echo str_replace( $find, $replace, $menu );

Hook to use dynamic class values before each span element in the menu “nav_menu_link_attributes” :

 

function add_specific_menu_location_atts( $atts, $item, $args ) {
if( $args->theme_location == ‘dashboard’ ) {
print_r($item);
exit;
foreach($item as $key => $value) {

if($key == ‘title’) {

if($value == ‘My Account’)
{
$catIcon = ‘fa-user’;
}else{

$catIcon = ‘fa-file-text’;
}
}
}
foreach($args as $key => $value) {
if($key == ‘link_before’) {
$args->$key = ‘<span class=”fa ‘.$catIcon.’ “></span>’;

}

}
// add the desired attributes:
$atts[‘class’] = ‘btn btn-primary btn-lg’;
}
return $atts;
}
add_filter( ‘nav_menu_link_attributes’, ‘add_specific_menu_location_atts’, 10, 3 );