Wordpress widget does not display - php

I have such a problem. On single.php page template, I display posts by categories. At the sidebar, I have the widget with related services and a bunch of tags that where I can filter displayed tags(using GET requests)
It looks like this:
<aside class='main__aside'>
<?php the_widget('some_wdgt',
array('title' => esc_html__('title', 'domain'),
'nav_menu' => 772));
?>
<?php
... some code with get params ...
?>
</aside>
Everything works fine, but when I apply filter widget with menu filter disappears. The only title of the widget is displayed.
Insdide widget code I display meny via:
...
echo $before_widget;
if ( $title ) {
echo $before_title . $title . $after_title;
}
wp_nav_menu( apply_filters( 'widget_nav_menu_args', $nav_menu_args, $nav_menu, $args, $instance ) );
echo $after_widget;
Why this is happening and how can I fix it? Thanks for your help.

May be it happens because of $nav_menu is WP_Term object, not number.
Please, look at this: widget_nav_menu_args. Hope it helps

Related

Can't show get_term output on the frontend

So i try to show a custom taxonomy on the frontend.
The custom taxonomy is from a plugin i use and is called wcs-instructor.
I just want to show a Single Page with the content of the taxonomy by listing the names and images of the Instructors, the image is a custom field.
When i try to Query the taxonomy with get_term or with WP_Term_Query everything shows up nicely as long as im logged in with my Admin Account (havent actually tested another account).
When i log out and open the Page again its blank.
The structur is as follows.
Custom Taxonomy: wcs-instructor
Page Endpoint: /trainer
Custom Single page: page-trainer.php
get_header();
?>
<main id="primary" class="site-main">
<?php
while ( have_posts() ) :
the_post();
get_template_part( 'template-parts/content', 'trainer' );
endwhile;
?>
</main><!-- #main -->
<?php
get_footer();
content-trainer.php (striped some html thats unnecessary)
<div class="content">
<?php
$term_query = new WP_Term_Query(
array( 'taxonomy' => 'wcs-instructor',) );
if ( ! empty( $term_query->terms ) ) {
foreach ( $term_query ->terms as $term ) {
echo $term->name;
}}
else {
echo 'No term found.';
}
?>
</div>
I know that the code above only gives me the results that are not empty, but the taxonomy got entries that aren't.
Also the Code below also doesn't work.
<?php
$terms = get_terms( array(
'taxonomy' => 'wcs-instructor',
'hide_empty' => false,
) );
foreach ( $terms as $term )
{
echo $term->term_id;
echo '<br>';
echo $term->name;
}
?>
And i just cant find the reason why because when i go to /wcs-instructor/testinstructor i can view the content even when im not logged in.
Any hints on how to debug this behavior or why it's behaving like this in the first place?
Sounds like that taxonomy might have the publicly_queryable arg set to false. Not sure which plugin you are using to manage your custom taxonomies but the CPT UI Plugin has a setting for that argument.
The Public Queryable setting for taxonomies in CPT UI plugin

How to remove the default meta title from functions.php in Wordpress?

Ok, so I have added my own title in the header.php
<title>
<?php
if (!(is_front_page())) {
wp_title('', true,''); ?> (<?php the_time( 'Y/m/d' ); ?>)-
<?php }
echo get_bloginfo( 'name' ); ?>
</title>
It works great.
The problem is that when I click on View Source, I see two title codes.
First one is my title that I manually added to header.php
And the second one is the default Wordpress title.
My question is, where do I need to modify (probably in the functions.php?) to remove the default Wordpress title?
Might be able to use this in your functions.php based on: wp-includes/default-filters.php
remove_action( 'wp_head', '_wp_render_title_tag' );
UPDATE
Based on your theme I recommend you remove your custom title from the header, remove the above remove_action i previously suggested and use the below solution in your functions.php. this will hook into the existing theme title and modify its value using your custom title code:
add_filter('wp_title', function($default_title){
$title = '';
if (!is_front_page()) {
$title .= wp_title('', false,'') .' '. get_the_time( 'Y/m/d' ) . '- ';
}
$title .= get_bloginfo( 'name' );
return $title;
});
Here's the working sulution. Just paste the below code to your functions.php:
remove_action( 'wp_head', '_wp_render_title_tag', 1 );

WordPress change search results

I have got the problem that my WordPress theme ("Sydney") is displaying the search results wrong. Instead of just listing posts I want to display WooCommerce products only.
Those should be ordered in a nice grid as shown in this picture:
.
At the moment the results are listed like this
.
How can I change the way the search results are displayed?
At the moment my search.php is looking like this:
<?php get_header(); ?>
<div id="primary" class="content-area col-md-9">
<main id="main" class="post-wrap" role="main">
<?php if ( have_posts() ) : ?>
<header class="page-header">
<h3><?php printf( __( 'Search Results for: %s', 'sydney' ), '<span>' . get_search_query() . '</span>' ); ?></h31>
</h3>
</header><!-- .page-header -->
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
/**
* Run the loop for the search to output the results.
* If you want to overload this in a child theme then include a file
* called content-search.php and that will be used instead.
*/
get_template_part( 'content', 'search' );
?>
<?php endwhile; ?>
<?php the_posts_navigation(); ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</main><!-- #main -->
</div><!-- #primary -->
Thank you guys a lot!
** UPDATE
The solution provided by kashalo partly worked, but search results still look slightly different from the product page and are listed in only one column instead of a grid.
** UPDATE
The solution suggested by Alexander Wigmore looks almost the way I wanted it so look like. The only Problem with copying the page.phpin the search.phpis that the products are still getting displayed wheird, but not when they are displayed in the category they fit in. For example: When searching for saat the results are displaying the products at first with text only, but normaly under the Saatgut category.
my advise is not to directly modify the search file of wp or theme template but is a good practice to work with the child theme. For the design display of the result you can play a little with css to customize it as you want, instead for the results to show only the products you can use any filter builded on the theme you are using (if it have) or create yourself a function to filter the results (also called hooks).
An example for filtering results is like the above code:
add_action( 'pre_get_posts', 'filter_woocommerce_products' ); // the hook
function filter_woocommerce_products( $query ) { // the function
if( ! is_admin() && is_search() && $query->is_main_query() ) {
// verify if can use the search function and the search string is from the search call
$query->set( 'post_type', 'product' ); // filter the posts with type products that corrispond to woocommerce products.
}
}
and this function must be saved on the function.php file of your theme or the child theme.
For more information i suggest you to read more about child theme and the pre_get_posts documentation on the wp page.
Hope it helps and feel free to ask.
You'll want to modify the way search is handled by Wordpress.
This can easily be done by adding an "action", add the below code to your functions.php file.
function searchfilter($query) {
if ($query->is_search && !is_admin() ) {
$query->set('post_type',array('product'));
}
return $query;
}
add_filter('pre_get_posts','searchfilter');
This will then make the search page only show products. It's worth noting that you can add other post types back in via the array in this line: $query->set('post_type',array('product'));.

Archive parameter not looping

I am using the wp_get_archives function to display a list of posts on my sidebar. Currently this does work as intended.
I want to build upon this sidebar by displaying get_the_title() and get_the_excerpt(). these also work.
However they are only displaying the current title and excerpt and not the corresponding title and excerpt to the current post.
Example:
Post 1 displays post 1's title and excerpt.
Post 2 displays post 1's title and excerpt.
Here is my full sidebar:
<aside id= "homeSideBar">
<?php if ( have_posts() ) {
while ( have_posts() ) {
the_post(); ?>
<?php }}
wp_get_archives( array( 'type' => 'postbypost', 'limit' => 10, 'after' => "<img class='showExcerpt' src=\"" . get_template_directory_uri() ."/images/plus-circle.png\"><div class='postExcerpt'><h1 class='fitHeadliner'>" . get_the_title() . "</h1><p>" . get_the_excerpt() . "</p><div class='hideExcerpt'>X</div></div>" ) ); ?>
...
</aside>
How can I make my posts display their corresponding titles and excerpts?
So as my sidebar gets more involved, I thought it best to refactor and create a sidebar.php template.
Within my sidebar.php template I use get_posts() within get_posts() you can use setup_postdata( $post ) to globalize post information like the_excerpt(), the_title(), etc.

Wordpress: echo a dynamic_sidebar widget inside of a shortcode

I'm trying to insert a widget into a shortcode that I'm storing in my footer.php file...
<?php
echo do_shortcode( '[accordion_full_width title="upcoming events" full_width="yes" background_color="#68676b"]' .
dynamic_sidebar( 'footer_contents' )
. '[/accordion_full_width]'); ?>
...and it renders out the widget first, followed by the shortcode.
If this is a problem with using the dynamic_sidebar function inside of the do_shortcode, I'd think it just wouldn't spit the widget out, but it does. In the wrong place.
Does anybody have anything?
Add this Code in Your Template
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Name of Widget') ) : ?>
<?php endif; ?>

Categories