display multiple feature images through custom post type with shortcode - wordpress

I have a shortcode/multiple feature image problem I'm hoping for a bit of help on.
My custom post type called rubow_medarbejder is displayed on a page with a shortcode. This works fine.
I need to add a second feature image. I've used the Multiple Featured Images plugin to do this. Problem is I can't get the image to display through my shortcode.
kd_mfi_get_featured_image_id() shows the id perfectly but when I type kd_mfi_get_featured_image() it brings this error message
Fatal error: Call to undefined function kd_mfi_get_featured_image() in /var/www/www.rubowarkitekter.dk/www/wp-content/plugins/Medarbejdere/medarbejdere_post_type_shortcode.php on line 22
The output part of my shortcode that provokes this error looks like this
$output .= '
<div id="medarbejder">
<div id="medarbejder-page-content-gray">' . kd_mfi_get_featured_image( 'hover-medarbejder-image-grayscale', 'rubow_medarbejder') . '</div>
<div id="medarbejder-page-content-img">' . get_the_post_thumbnail() . '</div>
<div id="medarbejder-page-content-navn">' . $meta['rubow_medarbejder_navn'][0] . '</div>
<div id="medarbejder-page-content-titel">' . $meta['rubow_medarbejder_titel'][0] . '</div>
<div id="medarbejder-page-content-telefon">' . $meta['rubow_medarbejder_telefon'][0] . '</div>
<div id="medarbejder-page-content-mail">' . get_the_content() . '</div>
</div>
';
Any hints to get this solved would be highly appreciated. Thanks!

Use Advanced Custom Fields plugin. Then add as much custom fields as you need. and use
echo get_field('my-other-featured-image');
To output.
You need to select image url and size in plugin to output like that.

Related

I can't debug whats wrong with my ACF get_field() to display an image array's url value

So my code is pretty straightforward. I am just getting a field value from the global fields (Options). So this field is on Dashboard -> Options (I have ACFpro) and I am trying to echo out a logo which is an image array.
This is how my code looks like
<ul class="text-white p-0">
<a class="brand " href="/">
<?php
$image = get_field('logo');
echo '<p id="debug">'.($image ['url']).'</p>';
?>
</a>
</ul>
al i am trying to do is pull the url value and insert it to a <p> tag just to make sure it pulls the right value. but instead I am getting this error.
error when trying to echo $image
Any idea on what am I doing wrong?
It is one of two things. You need to add the ID or options to the get_field() as a parameter or you need to adjust the return format. By default it tries to pull the ID of the page get_field() is on.
I would change it to
get_field( 'logo', 'options' );
Or change options to whatever you called your options page.
https://www.advancedcustomfields.com/add-ons/options-page/

how to edit $woo_options['woo_featured_height'

I have a old wordpress site that is defining some CSS using this code:
$fixed_height = ' style="height: ' . $woo_options['woo_featured_height'] . 'px;"';
<div class="slide <?php echo $css_class; ?>"<?php echo $fixed_height; ?>>
I cannot figure out where the $woo_options['woo_featured_height'] is defined. I have searched the entire codebase and there is no such value.
That's a woocommerce options array and most likely the option you are looking for comes from a database table and won't exists in your codebase. See this link for more information.

Wordpress ACF Plugin - wp_get_attachment_image function doesn't work with ACF Options Page?

I'm trying to get an image asset shown on the front-end using the wp_get_attachment_image WordPress function, but it doesn't seem to work with my options page on ACF.
Here is my code:
<?php
$image = get_field('logo', 'option');
$size = 'full'; // (thumbnail, medium, large, full or custom size)
if( $image ) {
echo wp_get_attachment_image( $image, $size );
}
?>
Which looks like this on the back-end:
The picture you see above is an options page in ACF and when I try to query that image into the wp_get_attachment_image function, it doesn't work. However, when I run this code:
<img data-src="<?php the_field('logo', 'option'); ?>" alt="footer logo" class="lazyload" />
which is within an image tag, it works just fine.
I copied and pasted what was shows on the ACF docs located here (Basic Display ID), but it's not showing the image on the front-end.
Anything I'm missing guys?
Thanks a lot!
Return value in field should be Image ID. See Screenshot
What is the return value type you used? Image Array, Image URL, Image ID
And you need to get a field like this:
get_field('logo'); why do you add option?
More info here:
https://www.advancedcustomfields.com/resources/image/
wp_get_attachment_image requires the first parameter to be an image ID. In your case, if you are seeing the image using the code <img data-src="<?php the_field('logo', 'option'); ?>" alt="footer logo" class="lazyload" /> then get_field('logo', 'option') is returning the url of the image.. not the ID which is what you need if you are using wp_get_attachment_image.
What you need to do is change the Return Value of your logo field to Image ID.
Then you might have to re upload the image.
And also change this code <img data-src="<?php the_field('logo', 'option'); ?>" alt="footer logo" class="lazyload" /> to <img data-src="<?php echo wp_get_attachment_url(get_field('logo', 'option')); ?>" alt="footer logo" class="lazyload" />
ACf plugin returns value as you have set the return type.
If you have sent the return type as Image array then :
$image[0] -> full or $image[0][$full] or $image[$full] depending on the number of image uploaded.
If you have set return type as Image url:
<img src="<?php $image; ?>"> would do the work.
If you are setting return type as Image Id:
$img2 = wp_get_attachment_image_src(get_post_thumbnail_id($image),
$full); echo $img2[0];
I guess above methods will surely help you out.
Thanks

Wordpress Mobile Menu Plugin

https://tr.wordpress.org/plugins/mobile-menu/
the plugin I am using
But my problem, Plugin search link;
mywebsite.com/?s=searchtitle
but what I want;
mywebsite.com/?s=searchtitle&post_type=product
I think it might be relevant code section;
$header_search = '<i class="mob-icon-search-6 mob-search-button"></i><i class="mob-icon-cancel mob-search-cancel-button"></i>';
$header_search .= '<div class="mobmenu-search-holder"><form class="mob-menu-search-form" action="" method="get">
<input type="text" name="s" class="mob-menu-search-field" placeholder="' . $titan->getOption( 'placeholder_text' ) . '" autofocus="">' . $search_button . '</form></div>';
I'm author of WP Mobile Menu. You can achieve this in several ways.
Try the solution in this topic.
https://wordpress.stackexchange.com/questions/223576/changing-a-themes-search-function-to-only-show-results-from-woocommerce

How to wrap HTML/PHP concatenation in Wordpress Function

I'm making my first basic Wordpress Theme, and trying to create a function to retrieve and display the first 6 posts, which I could use in various areas depending on the page you're on. It is very similar to this tutorial, that I found... after facing the fact it doesn't work in my theme.
Here is a simplified piece of the code (I tried several versions) :
function show_last_items() {
while ( have_posts() && $count < 6) :
the_post();
$count++;
print '<article id="post-'.the_ID().'" class="post-link-display">
<a href="'.the_permalink().'" title="'.the_title_attribute().'">
<div class="date">
<p>'.the_time( 'd/m' ).'</p>
</div>
<div class="title">
<h6>'.the_title().'</h6>
</div>
</a>
</article>';
endwhile;
}
For some reason, while the code inside the function works just fine if I use it directly on a template part (for example sidebar.php), all the HTML seems to be wiped off when used as a function... Or more exactly, it still exists, but in-between the data. So I get something like this displayed :
55http://localhost/myTheme/posts/55/my-post-title/My post title19/03My
post title
56http://localhost/myTheme/posts/56/my-other-post-title/My other post
title19/03My other post title
Yet the <article> tag and every markup in it is still there, empty, after each line that displays the retrieved information. I'd really like to understand why the concatenation doesn't work properly in this case. Is it something about the theme support ? It doesn't seem to me the WP_Widget class would change anything to this issue, but maybe I'm wrong ?
Try this
function show_last_items() {
while ( have_posts() && $count < 6) :
the_post();
$count++;
sprintf('<article id="post-%s" class="post-link-display">
<a href="%s" title="%s">
<div class="date">
<p>%s</p>
</div>
<div class="title">
<h6>%s</h6>
</div>
</a>
</article>', the_ID(), the_permalink(), the_title_attribute(), the_time( 'd/m' ), the_title());
}
Have you tried building a string and then returning it?
$return_string = '';
// while loop
$return_string .= '<article .....';
// end while
return $return_string;

Resources