Custom Taxonomy Template won't show any menus - wordpress

This is how I can start describing this, it's a very strange error that maybe something else but this is the first symptom I have.
I have a custom template[taxonomy-location_types.php] that shows, a custom post type [locations] by it's custom taxonomy[location-types].
If you visit the home page you will see a menu editorial, travel, etc.
Now if you look here on this taxonomy page
The menu is gone, there are other queries that aren't firing but I'm focussing on this as a primary issue.
I have generated output from nav-menu-template.php like so:
if ( $menu && !is_wp_error($menu) && !isset($menu_items) )
{
write_log($menu);
$menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'update_post_term_cache' => false ) );
write_log($menu_items);
}
and I get this:
[31-Aug-2017 15:27:52 UTC] WP_Term Object
(
[term_id] => 2
[name] => Header Menu
[slug] => header-menu
[term_group] => 0
[term_taxonomy_id] => 2
[taxonomy] => nav_menu
[description] =>
[parent] => 0
[count] => 6
[filter] => raw
)
[31-Aug-2017 15:27:52 UTC] Array
(
)
[31-Aug-2017 15:27:52 UTC] WP_Term Object
(
[term_id] => 3
[name] => Footer One
[slug] => footer-one
[term_group] => 0
[term_taxonomy_id] => 3
[taxonomy] => nav_menu
[description] =>
[parent] => 0
[count] => 5
[filter] => raw
)
[31-Aug-2017 15:27:52 UTC] Array
(
)
So it sees the menu but for some reason return no items in either menu.
I have turned off all plugins and still get the same result, I have also eliminated all other queries on this page to see if there was conflict and this still this happens.
Any insight on this one would be great not sure where to look next for issues.

Chalk another one up for RTFM, I had a pre_get_posts hook altering the query and I didn't ensure that the query it was altering was just the $query->is_main_query() because strangely enough this alteration was getting into the nav_menu query.
query monitor is now my new best friend.

Related

get_the_category() wordpress function stopped working after updating core version

As the title says - i have a single.php template which gets the category of the current post assigned.
$cat_post = get_the_category();
That function returns the category which is assigned to the post. After upgrading from 4.0.24 to 4.9.7 it stopped working. The only thing that comes to my mind is that the function is not supported but i haven't found something about this.
Any ideas?
you can use this
//get category
$category = get_the_category(get_the_ID());
//the above code will return an Array
Array
(
[0] => WP_Term Object
(
[term_id] => 2
[name] => video
[slug] => video
[term_group] => 0
[term_taxonomy_id] => 2
[taxonomy] => category
[description] =>
[parent] => 0
[count] => 1
[filter] => raw
[cat_ID] => 2
[category_count] => 1
[category_description] =>
[cat_name] => video
[category_nicename] => video
[category_parent] => 0
)
)
// you can access this array like this
$catID = $category[0]->term_id;
//for term id
$catName = $category[0]->name;
//for category name
I think you are trying to get a category from the current post which is the custom post type.
As per the documentation of the following function, it doesn't work for the custom post type. You can see it on the link below.
Click here to see the Code Reference
For custom post type, you can use get_the_terms() method. Here is the link of the Code Reference of the function.

Override functionalities in Woocommerce Reports section

I need to customize the Reports in WooCommerce, so I have to edit the core file class-wc-report-sales-by-date.php, such file doesn't use any hook.
Check this in WC source code: includes/admin/reports/class-wc-report-sales-by-date.php
I have to edit the 393 line, this variable: $this->report_data->total_sales
I need to customize the Total Sales amount to add it another value.
How can I override WooCommerce this core file?
Never override core files… There is other ways made for that. If you look at line 411, you have woocommerce_admin_report_data filter hook to make changes, this way (example):
add_filter( 'woocommerce_admin_report_data', 'custom_admin_report_data', 10, 1 );
function custom_admin_report_data( $report_data ){
// HERE you make your calculations and changes
// New amout to set (example)
$new_calculated_amount = 100;
// Set the new amounts for "total_sales" key
$report_data->total_sales = $new_calculated_amount;
// Raw data output just for testing, to get the keys and the structure of the data
// to be removed
echo '<pre>'; print_r($report_data); echo '</pre>';
// Return the changed data object
return $report_data;
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested and works.
I have included a line of code that outputs the raw data that you should remove… It's just to see the data structure and the changes made by the function on the "total_sales" value…
The Raw data output is something like this (that gives you the data structure to better make changes):
stdClass Object
(
[order_counts] => Array
(
[0] => stdClass Object
(
[count] => 1
[post_date] => 2017-11-21 16:45:43
)
)
[coupons] => Array
(
)
[order_items] => Array
(
[0] => stdClass Object
(
[order_item_count] => 1
[post_date] => 2017-11-21 16:45:43
)
)
[refunded_order_items] => 0
[orders] => Array
(
[0] => stdClass Object
(
[total_sales] => 48
[total_shipping] => 15
[total_tax] => 5
[total_shipping_tax] => 3
[post_date] => 2017-11-21 16:45:43
)
)
[full_refunds] => Array
(
)
[partial_refunds] => Array
(
)
[refund_lines] => Array
(
)
[total_tax_refunded] => 0
[total_shipping_refunded] => 0
[total_shipping_tax_refunded] => 0
[total_refunds] => 0
[total_tax] => 5.00
[total_shipping] => 15.00
[total_shipping_tax] => 3.00
[total_sales] => 48.00
[net_sales] => 25.00
[average_sales] => 3.57
[average_total_sales] => 6.86
[total_coupons] => 0.00
[total_refunded_orders] => 0
[total_orders] => 1
[total_items] => 1
)
So as you can see you also need to make changes on the "orders" object data as you also have the "total_sales" key…

Wordpress query all categories for recent and always from specific categories limit

I seen other questions regarding something similar but nothing exactly like I need. I want to query the wp database for the most recent 6 posts. However, I always need it to pull one post from two certain categories.
To sum up: Pull 4 recent posts and always grab one from two specific categories totaling 6 posts. How can this be achieved? Right now I am able to pull 6 recent posts but I am not able to tell it to always pull 1 post from two other categories regardless if they are recent or not.
Array //$args
(
[post_status] => publish
[posts_per_page] => 6
[ignore_sticky_posts] => 1
[post_type] => post
[meta_key] => _thumbnail_id
[suppress_filters] =>
[] => Array
(
[0] => Array
(
[taxonomy] => category
[field] => id
[terms] => Array
(
)
)
)
)
$carousel_query = new WP_Query( $args );
if ( $carousel_query->have_posts() ) :
while ( $carousel_query->have_posts() ) : $carousel_query->the_post();
........
endwhile;
endif;

Drupal hook before or after render() function

I have a problem with my drupal page. We use the opigno tool (its a module to that allows to create course - nodes which can be bought).
Now we have a problem with the view of the course-node. Everything works fine until a user bought the course and the drupal commerce status is on "pending". The problem now is that the node is showing nothing except the title of the course.
I began to think whats going on and took a look to the view settings for the course-view. Nothing (no Permission was set, no filter criteria ...)
Then I took a look at the template override of the course-view. And then I saw smth ...
print render($content['body']);
Ah! A render function to render the content of the view. So I asked myself: What is in content ?
After printing out the $content variable I saw this:
Array
(
[body] => Array
(
[#theme] => field
[#weight] => 1
[#title] => Description
[#access] =>
[#label_display] => hidden
[#view_mode] => full
[#language] => und
[#field_name] => body
[#field_type] => text_with_summary
[#field_translatable] => 0
[#entity_type] => node
[#bundle] => course
[#object] => stdClass Object
(
[vid] => 185
[uid] => 60
[title] => Demo Course
[log] =>
[status] => 1
[comment] => 1
[promote] => 0
[sticky] => 0
[vuuid] => 16e7999b-28bb-4f3e-8bed-54a21b17f398
[nid] => 176
[type] => course
[language] => und
[created] => 1406897520
[changed] => 1407145285
[tnid] => 0
[translate] => 0
[uuid] => 22baf19a-dc32-4137-b698-89f1bb4adc59
[revision_timestamp] => 1407145285
[revision_uid] => 1
[body] => Array
(
[und] => Array
(
[0] => Array
(
[value] =>
This is a sample course for beta testers, it will show you the structure of the courses.
Here usually is displayed the description of the course.
Please "enroll" if you want to see the contents of this demo course.
[summary] => This is a sample course for beta testers to help you see the structure of a course. Please have a look on it!
[format] => html
[safe_value] =>
This is a sample course for beta testers, it will show you the structure of the courses.
Here usually is displayed the description of the course.
Please "enroll" if you want to see the contents of this demo course.
[safe_summary] => This is a sample course for beta testers to help you see the structure of a course. Please have a look on it!
)
)
)
)
Aaah! So $content has the content, but its not printed out with render()! But why ?
I searched in google for a hook which are able to "override" the render function and maybe deny the output when the user is on "pending". But... nothing.
I found this hook:
{hook}_node_view()
I searched for a using of this hook in all modules but when deleteing these functions from the modules did not changed anything. Are there other options to "override" the render() function ? Another hooks I can search for ? Or maybe you had the same problem with opigno ?
I am sorry - the problem was the Opigno Field Access Module. I deactivated it and it works like a charm.

Unpredictable CCK field name in returned View data

I'm using views_get_view_result to directly access the data in a view. I've stumbled upon this odd behavior where cck fields are prefixed with the first field name as a query optimization. Explained here.
What's bizarre though is that fields are named differently depending on whether I retrieve that data as Anonymous or as Admin. I'm pretty sure all my permissions are set up, and the view itself has no restrictions. What is going on here?
This is a big problem since I can't know how to retrieve a field. Here's a dump of the two view results. Notice that node_data_field_game_date_field_game_home_score_value != node_data_field_game_official_field_game_home_score_value.
// View as Admin
stdClass Object
(
[nid] => 3191
[node_data_field_game_date_field_game_date_value] => 2010-03-27T00:00:00
[node_type] => game
[node_vid] => 5039
[node_data_field_game_date_field_game_official_value] => 0
[node_node_data_field_game_home_team_title] => TeamA
[node_node_data_field_game_home_team_nid] => 3396
[node_data_field_game_date_field_game_home_score_value] => 68
[node_node_data_field_game_visitor_team_title] => TeamB
[node_node_data_field_game_visitor_team_nid] => 3442
[node_data_field_game_date_field_game_visitor_score_value] => 118
)
// View as Anonymous
stdClass Object
(
[nid] => 3191
[node_data_field_game_date_field_game_date_value] => 2010-03-27T00:00:00
[node_type] => game
[node_vid] => 5039
[node_data_field_game_official_field_game_official_value] => 0
[node_node_data_field_game_home_team_title] => TeamA
[node_node_data_field_game_home_team_nid] => 3396
[node_data_field_game_official_field_game_home_score_value] => 68
[node_node_data_field_game_visitor_team_title] => TeamB
[node_node_data_field_game_visitor_team_nid] => 3442
[node_data_field_game_official_field_game_visitor_score_value] => 118
)
Very weird behavior. Maybe it's a problem with content permission?

Resources