Taxonomy Custom field image is not showing - wordpress

I want to show taxonomy custom field images on loop on the home page
"developers" is taxonomy name
and "developer_logo" is image field slug
I used that code only name is showing but image is not showing
<?php
$terms = get_terms( array( 'taxonomy' => 'developers', 'hide_empty' => false ) );
$image = get_field('developer_logo');
foreach ( $terms as $term ) : ?>
<div class="col-lg-4 col-md-6">
<div class="product product-zoom product--card">
<div class="product__thumbnail">
<img src="<?php echo esc_url($image['url']); ?>" alt="<?php echo $term->name; ?>">
</div>
<div class="product-desc">
<h4 class="text-center mb-2"><?php echo $term->name; ?></h4>
</div>
</div>
</div>
<?php
endforeach
?>
I just want to show the images of taxonomy custom field

**In the below code, i have added the term Id as second parameter in get_field() function to get image URL & replaced the $image variable from outside of loop to inside the foreach loop.**
<?php
$terms = get_terms(array(
'taxonomy' => 'developers',
'hide_empty' => false
));
foreach ($terms as $term) {
$image = get_field('developer_logo', $term->id); ?>
<div class="col-lg-4 col-md-6">
<div class="product product-zoom product--card">
<div class="product__thumbnail">
<img src="<?php echo $image; ?>" alt="<?php echo $term->name;?>">
</div>
<div class="product-desc">
<h4 class="text-center mb-2"><?php echo $term->name;?></h4>
</div>
</div>
</div>
<?php
}
?>

Related

How can I wrap the content using a permalink in a foreach loop

How can I wrap the content in the overlay div with a permalink that corresponds to the category. I want the image to be clickable and also pull the category name with the matching image. I want this to be dynamic in the event new categories are added.
<?php
/**
*
* Catergory Display
*
*/
$categories = get_categories( array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => false,
) );
?>
<div class="container">
<div class="row">
<?php
foreach( $categories as $category ) {
$image = get_field('category_image', 'category_' . $category->term_id);
$size = 'featured-thumbnail'; // (thumbnail, medium, large, full or custom size)
$cat_link = get_category_link($category->cat_ID);
?>
<div class="category-holder col-lg-4 col-md-6 col-sm-12 ">
<div class="category-display-img">
<?php echo wp_get_attachment_image( $image, $size ); ?>
<a href="<?php echo esc_url( get_permalink($cat_link) )?>">
<div class="overlay"><?php echo '<a class="" href="'.$cat_link.'">'.$category->name.'</a>'; // category link ?></div>
</a>
</div>
</div>
<?php
// echo '<pre>';
// print_r($cat_link);
// wp_die();
} ?>
</div>
</div>
You can wrap the anchor tag around the div with the overlay class.
Delete this part
<a href="<?php echo esc_url( get_permalink($cat_link) )?>">
<div class="overlay"><?php echo '<a class="" href="'.$cat_link.'">'.$category->name.'</a>'; // category link ?></div>
</a>
And use this in its place
<a href="<?php echo $cat_link ?>">
<div class="overlay">
<?php echo $category->name ?>
</div>
</a>

Custom Taxonomy List Wordpress

I'm really a beginner for creating and displaying custom tax on WordPress.
I created a custom Genre taxonomy and I'm displaying this with this:
<?php $terms = get_the_terms( get_the_ID(), 'movie_genre' ); if( $terms ): ?>
<!-- Movie Genre -->
<div class="slideout-heading">
<div class="d-inline-block">
<h5><?php esc_html_e( 'Genre'); ?></h5>
</div>
</div>
<div class="row">
<div class="carousel mb-3 w-100" data-flickity='{ "pageDots": false, "imagesLoaded": true, "prevNextButtons": true, "cellAlign": "left", "contain": true, "groupCells": true }'>
<?php foreach( $terms as $term ): ?>
<?php
$attachment_id = get_field('taxonomy_image', $term);
$size = "wp-img-square-profile"; // (thumbnail, medium, large, full or custom size)
$genreimage = wp_get_attachment_image_src( $attachment_id, $size );
?>
<div class="col-3 py-3">
<div class="mb-2">
<a href="<?php echo get_term_link( $term ); ?>">
<?php if( $attachment_id ) {
echo '<img class="img-fluid border-class shadow-sm" src="'. $genreimage[0] .'" />';
} else {
wp_default_img_placeholder();
}
?>
</a>
</div>
<div class="author-list-name px-1">
<?php echo esc_attr ($term->name); ?>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
</div>
</div>
</div>
How could I display Genres Parent & Child together another and other? I can display selected parent and child for the custom taxonomy but could not relate with a parent it's just showing one by one not related with the parent but I would like to relate the group Parent-Child :)
-Action
best actor
best music
-Adventure
best music
output
Custom_Movie_Genre_Taxonomy
Thanks a lot for your help!

Can't display custom post type categories on the page

I have a custom post type called "case_studies" and it has 3 categories: "seo", "website-design" and "facebook-advertising".
I have several posts in the main page, and for each post I want to output what categories the post has.
For example, the latest post has a category of "seo" and "facebook-advertising", and I want it to be displayed in the page.
I have tried the get_the_terms(); function but I think I am using it incorrectly.
Here is the code of the page:
<div class="container">
<!--
<div class="category_container">
<p class="category_item" id="all">All</p>
<p class="category_item" id="website">Websites</p>
<p class="category_item" id="facebook">Facebook Ads</p>
<p class="category_item" id="seo">SEO</p>
</div>
-->
<div class="row d-flex">
<?php
$args1 = array( 'post_type' => array('case_studies'), 'order' => 'DESC', 'posts_per_page' => 30, 'orderby' => 'date' );
$loop = new WP_Query( $args1 );
while ( $loop->have_posts() ) {
$loop->the_post();
$feat_image = wp_get_attachment_url( get_post_thumbnail_id($loop->ID));
?>
<div class="col-sm-4">
<div class="case-study-content">
<a href="<?php the_permalink() ?>" class="blog_blocks">
<div class="b_image">
<img src="<?php echo get_the_post_thumbnail_url(); ?>"/>
</div>
<div class="b_h_sec">
<h2><?php the_title(); ?></h2>
<p><?php echo wp_strip_all_tags( get_the_excerpt(), true ); ?></p>
<span class="r_m">Read More</span>
</div>
</a>
</div>
</div>
<?php } ?>
<?php wp_reset_postdata(); ?>
</div>
</div>
Here is how the output looks right now and where I want categories to be displayed.

Wordpress query category name and related posts

I am trying to query Wordpress custom posts and categories they are related to.
Query acts strangely, displays category name and all customs posts, not even related to that category (keeps repeating till all categorie names are displayed.)
Example image : Wordpress custom query display
My query code:
<div id="page-content-wrapper">
<div class="container-fluid">
<div class="lookbook-header">
<div class="wrap">
<p class="text-left">lookbook</p>
</div>
</div>
<?php
$taxonomy = 'lookbook_categories';
$terms = get_terms($taxonomy);
$args=array(
'taxonomy' => 'lookbook_categories'
'post_type' => 'lookbook',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if ( $terms && !is_wp_error( $terms ) ) :
foreach ( $terms as $term ) { ?>
<div class="lookbook-category">
<p class="text-center">
<?php echo $term->name; ?>
</p>
</div>
<?php
if( $my_query->have_posts() ) {
echo '';
$count=0;
while ($my_query->have_posts()) : $my_query->the_post();
if($count == 3) {?>
<div class="row">
<?php }
?>
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 no-padding">
<div class="lookbook-item">
<div class="hvrbox">
<?php
$image = get_field('lookbook_image');
if( !empty($image) ): ?> <img src="<?php echo $image['url']; ?>" alt="news" class="img-responsive" />
<?php endif; ?>
<div class="hvrbox-layer_top">
<div class="hvrbox-text">
<div class="separator"></div>
<h3><?php the_title();?></h3>
<div class="separator"></div>
<p>
<?php the_field('excerpt');?>
</p>
</div>
</div>
</div>
</div>
</div>
<?php
$count++;
if($count == 3) echo '</div>';
endwhile;
}
}
endif;
wp_reset_query();
?>
</div>
</div>
I would like to display category name + posts related to category (not all posts over and over again)
You want to pass in an array to get_terms like:
$terms = get_terms( array(
'taxonomy' => 'lookbook_categories',
'hide_empty' => false,
) );
you can read more about it here: https://developer.wordpress.org/reference/functions/get_terms/

WP Query Multiple Shortcodes not working on same page or template page

I created a Shortcode slider which gets ids of different pages and show display slider. Shordcode works fine but issue is that whenever i am copy past shortcode multiple times on same page/ template page it shows only first one.
This issue occurs only only when i past same type of shortcode but if i past any other shortcode on same page it works fine.
Here is my code
add_shortcode( 'objectx-pages-list', 'objectx_pages_list_func' );
function objectx_pages_list_func( $atts ) {
global $post;
ob_start();
extract( shortcode_atts( array('ids' => '1186'), $atts ) );
$id_array = explode(',', $ids);
$pages_query = new WP_Query( array(
'post_type' => 'page',
'post__in' => $id_array,
'order' => 'ASC',
'orderby' => 'title',
) );
if ( $pages_query->have_posts() ) { ?>
<div class="carousel-wrapper">
<div class="owl-carousel owl-theme carousel-1" id="carousel-rooms">
<?php while ( $pages_query->have_posts() ) : $pages_query->the_post();
$featured_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
?>
<div <?php post_class('item'); ?> id="post-<?php the_ID(); ?>">
<div class="row">
<div class="col-md-7">
<div class="img-rooms">
<a href="<?php the_permalink(); ?>">
<img class="img-responsive wp-post-image" src="<?php echo $featured_image; ?>"></a>
</div>
</div>
<div class="col-md-5">
<div class="detail-rooms">
<h2 class="title-room "><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
</div>
<?php $myvariable_pages = ob_get_clean();
wp_reset_postdata();
return $myvariable_pages;
}
}
Here is shortcode
[objectx-pages-list id="15,16,17"]
[objectx-pages-list ids="25,26,27"]
here you can see live example
http://objextheme.wpengine.com/
This one working fine
ROOFTOP PATIO & LOUNGE
but this is not working
This Week At Vertigo Sky Lounge
Please guide me where i am doing mistake. Thanks
add_shortcode( 'objectx-pages-list', 'objectx_pages_list_func' );
function objectx_pages_list_func( $atts ) {
global $post;
ob_start();
extract( shortcode_atts( array('ids' => '1186'), $atts ) );
$id_array = explode(',', $ids);
$pages_query = new WP_Query( array(
'post_type' => 'page',
'post__in' => $id_array,
'order' => 'ASC',
'orderby' => 'title',
) );
if ( $pages_query->have_posts() ) { ?>
<div class="carousel-wrapper">
<div class="owl-carousel owl-theme carousel-1" id="carousel-rooms">
<?php while ( $pages_query->have_posts() ) : $pages_query->the_post();
$featured_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
?>
<div <?php post_class('item'); ?> id="post-<?php the_ID(); ?>">
<div class="row">
<div class="col-md-7">
<div class="img-rooms">
<a href="<?php the_permalink(); ?>">
<img class="img-responsive wp-post-image" src="<?php echo $featured_image; ?>"></a>
</div>
</div>
<div class="col-md-5">
<div class="detail-rooms">
<h2 class="title-room "><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
</div>
<?php $myvariable_pages = ob_get_clean();
wp_reset_postdata();
return $myvariable_pages;
}
}
Here is the error i noticed. id="carousel-rooms" Id repeating on
same page. that is why only one time it runs perfect.

Resources