woocommerce show the categories image on the page - wordpress

im solving this for two days is there anyone there to help me. Im using Tweenty thirteen themes for wordpress customize it and i install the category listing plugins to show the image category but it sems on the side bar is no problem but in the content is showing this "Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\barfly\wp-content\plugins\woocommerce-category-widget\woocommerce-category-widget.php on line 445
"

Which version of woocommerce and wordpress are you using? Woocommerce are now on 2.3 and they under went lot of changes. Its not just about the foreach loop, even if you solved it, it would still need other changes.
What i would suggest is update woocommerce, wordpress and your listing plugin to the latest version. Secondly it looks like the category listing plugin you are using doesnot support the new version of woocommerce, Make sure it supports the latest version of woocommerce.
EDIT:
place this code within the loop, it will get thumbnail from the category and display them after the Category title.
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );
if ( $image ) {
echo '<img src="' . $image . '" alt="" />';
}

Related

WP multisite ACF get_field() restores to current site

I'm getting really frustrated with this issue I am having with WP multisite.
The idea is, I have a multisite and it is here where all posts are created then just shared down to the other sites using ACF field.
Here is a part of the code where the issue happens:
switch_to_blog(1);
$person= get_posts( $args );
foreach($person as $post) {
echo get_current_blog_id(); THIS WILL DISPLAY 1
$person_info = get_field('person_info', $post->ID);
echo get_current_blog_id() ; THIS WILL DISPLAY THE CURRENT SITE, THE SITE JUST GOT RESTORED
}
restore_current_blog();
Can anybody help me figure out what is happening please?
TIA

Woocommerce getting custom field values in cart and checkout

I am trying to get the custom field value of a WooCommerce product to display on different pages of the shop system. I succeeded to do so for the single product page, but the same code doesn't work for the cart.
For the single product I used this code within the functions.php, which works fine:
global $post;
echo '<p>' . get_post_meta($post->ID, 'my-custom-field', true) . '</p>';
I tried the same code for the cart, but this time the values don't show on the page. I also referred to this thread (Woocommerce getting custom attributes), changing $post to $product, but still no output...
Any suggestions?
<?php
echo get_post_meta( get_the_ID(), 'slug/id', true );
?>
You Can try this, This works for me Very well.

Adding media support to a timeline plugin (Wordpress)

I have installed this plugin -> http://wordpress.org/plugins/wordpress-posts-timeline/ .
With this plugin you can create a post and it displays in a timeline. My problem is that images don't show when inserted in the post box.
I tried modifying the plugin code and put some get_attachment code inside the loop there but unfortunately didn't work.. I can get all images to show, but not by ID of the post.
Youtube support would be nice too, but maybe that gets clear if this question is answered.
Current state -> http://erwin.my89.nl/stage/sieh
// Edit
I have tried alot of code with wp_get_attachment stuff.
<?php
wp_get_attachment_image( $attachment_id, $size, $icon );
?>
&
<?php $uri = wp_get_attachment_image_src( $post->ID, 'medium' );
echo $uri[0];?>
But cant get it to work..
Thanks in advance.
The plugin is stripping HTML tags when building the content:
function timeline_text($limit){
$str = get_the_content('', true, '');
$str = strip_tags($str);
// etc...
You have to add <img> (and others) as an allowed tag on strip_tags():
$str = strip_tags($str, '<img>');

Advanced Custom Fields inside a plugin

I'm having some problems receiving data from the ACF plugin inside a plugin.
I'm using owl carousel to display a slideshow but i would like to add some extra text fields per image.
I created 2 caption fields in ACF and linked them to the post type of Owl Carousel.
implemented the fields inside the Owl Carousel main php file like so:
$caption1 = get_field('owl_caption1');
$caption2 = get_field('owl_caption2');
$loop = new WP_Query($args);
while ($loop->have_posts()) {
$loop->the_post();
$the_url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), $type);
$result .='<div class="item"><img title="' . get_the_title() . '" src="' . $the_url[0] . '" alt="' . get_the_title() . '"/><p>'.$caption1.'</p><p>'.$caption2.'</p></div>';
I also added the include line to the top of this document (plugins/owl-carousel/owlcarousel.php) to receive the date but when i fill in the fields they are not displaying
include_once('advanced-custom-fields/acf.php' );
The Faq of ACF states that you need to include the files inside your theme (themes/themename/advanced-custom-fields) or plugin (plugins/owl-carousel/advanced-customfields) so i tried copying the acf folder to my theme folder and the Owl Carousel plugin folder but i can't seem to receive the data.
Thanks in advance!

Display specific WordPress categories on a page without a plugin

I'm trying to display a specific category on a WordPress page using a shortcode. I'm familiar with making a custom page template and calling the category there, however my end users will have to be able to add more categories without creating new page templates for each.
Essentially I'm looking for how to create a shortcode that would call a specific category of posts on a page without creating a custom template or using a plug-in.
Thanks!
Here is a simple example. Modify it as needed.
add_shortcode('catlist', function($atts, $content) {
$atts += array('category' => 1);
$posts = get_posts("category={$atts['category']}");
foreach ($posts as $post) {
echo $post->post_name . '<br />';
}
});
echo do_shortcode('[catlist category=5]');
Look at source code of this plugin - http://wordpress.org/extend/plugins/category-post-shortcode/ and you find the solution (approximately 50 lines of code).

Resources