Shortcode inside other shortcode Wordpress ACF - wordpress

how to use this function correctly:
<?php echo do_shortcode('[product id="<?php the_field('wyrozniony_produkt_id')?>"]'); ?>
I need write inside this in place 3931
<?php echo do_shortcode('[product id="3931"]'); ?>
This shortcode (textfield from ACF)
<?php the_field('wyrozniony_produkt_id')?>
Anyone have idea how to make this?

your syntax seems to be wrong
please check the updated code of yours
<?php
$product_id = get_field('wyrozniony_produkt_id');
echo do_shortcode('[product id="'.$product_id.'"]');
?>

Related

ACF fields on WooCommerce Product not displaying

I am customizing an old theme called AmazeTheme which was not specifically made with WooCommerce support. And an woocommerce.php was at theme's root. However with help of plugins like Simply Show Hooks and Show current template I am able to see where to put which info.
But I am having an weird problem. The ACF fields I have added are not visible at all. I even tried to assign the field group inside product loop section.
I also tried the following method.
add_action( 'woocommerce_after_single_product_summary', 'view_acf_field_for_single_product', 10 );
function view_acf_field_for_single_product(){
if (function_exists('the_field')){
the_field('shop_support');
}
}
And inside the loop of single-product.php
<?php while ( have_posts() ) : the_post(); ?>
<?php wc_get_template_part( 'content', 'single-product' );
$dump = get_fields();
?>
<?php endwhile; // end of the loop. ?>
And then did var_dump($dump) at desired place of the file.
This site's php version is 5.6.40 and WooCommerce version is 3.4.8
WP version is 4.9.18
I have looked up many solutions. Also tried the WooCommerce Hooks but still no clue why ACF not showing.
Can you try this code:
add_action( 'woocommerce_after_single_product_summary', 'view_acf_field_for_single_product', 10 );
function view_acf_field_for_single_product(){
global $post;
if (function_exists('the_field')){
the_field('shop_support', $post->ID);
}
}
Not tested.
For some weird reasons, this approach worked for me (path/to/theme/woocommerce/single-product.php):
<?php if (get_field_objects()):
foreach ( get_field_objects() as $field_id => $field ) :
$value = trim($field['value']);
if (!empty($value)) :
?>
<div class="product_field" id="field-<?php echo $field_id; ?>">
<?php the_field($field_id); ?>
</div>
<?php endif; ?>
<?php endforeach; // end of the loop. ?>
<?php endif; ?>
Also the following one for Category (path/to/theme/woocommerce/archive-product.php) pages:
<?php
$extra_info = get_field_object( 'category_details', get_queried_object() );
if ( !empty($extra_info) ) :
?>
<div class="category_field" id="field-<?php echo $extra_info['key']; ?>">
<?php echo $extra_info['value']; ?>
</div>
<?php endif; ?>
Even at these locations, get_fields() did not work.

How to get page title in wordpress

Well, I have tried
<?php echo get_the_title('About Us');?>
But the code is not working. I am using wordpress 4.1. This should work but it isn't. Has wordpress updated the functions?
Try this one, It's may help you
<?php single_post_title(); ?>
Thanks :)
Try this one,may it's help you
<?php echo get_the_title(); ?>
And if you want to get page or post title By id
<?php echo get_the_title(post->$ID); ?>
Thanks
You are giving wrong parameters to get_title. See the codex.
You should have used ID instead to get the title.
So your code would be
<?php echo get_the_title(13); //where 13 is the ID of the about us page ?>
NOTE: Parameters are optional.
You could use the_title() to display the title of the page. You can pass parameters for before and after HTML tags. For morr information, here are the docs:
https://developer.wordpress.org/reference/functions/the_title/
<?php
the_title();
?>
You can try this
<?php echo get_page_by_title( 'About' ); ?>
Reference
<?php
$page = get_page_by_title( 'About Us' );
echo get_the_title($page->ID)
?>

Diamond MultiSite Widget

I am using Diamond MultiSite Widget in my site. Alongwith post title, url, description, I also want to display the post thumbnail. I have tried many times, contacted the plugin author for help but in vein. Does anyone know how to do it?
Ref: Please check 'Latest Questions' block in this quotation page.
Thanks.
First of all, you have to get the post id to belong that you get a post thumbnail image of that
Second, you have to display the post-featured Image.
Then this code is not working. please specify your actual requirement.
<?php $pages = get_pages(array('child_of' => 1)); ?>
<?php foreach ($pages as $page): ?>
<?php echo get_the_post_thumbnail($page->ID, 'thumbnail'); ?>
<h1><?php echo $page->post_title; ?></h1>
<?php echo $page->post_content; ?>
<?php endforeach; ?>

how to append php code in the shortcode in wordpress

I am using the shortcode in the loop inside template file
and also using the lightbox form plugin.
<?php query_posts('showposts=9&post_type=packages') ?>
<?php while (have_posts()) :the_post(); ?>
<?php echo the_post_thumbnail(); ?>
...
...
<?php echo do_shortcode("[formlightbox text='Book Now' title=the_title][contact-form-7 id='383' title='Booking Form'][/formlightbox]"); ?>
<?php endwhile; ?>
Please note that in the shorcode there is title=the_title and it is not appened to the anchor tag.
But when I use title='hello'or something else it gets appended to the anchor tag.
I want current post's title should get appened to the rendered anchor tag via shortcode.
please help me
Break the string and use the string concatenation operator to combine the function into your string.
<?php echo do_shortcode("[formlightbox text='Book Now' title='" . get_the_title() . "'][contact-form-7 id='383' title='Booking Form'][/formlightbox]"); ?>
Update
This should use the get_the_title() as opposed to the_title() which echos the title.

Themeing in views , drupal 7

Goal : To add a div wrapper for the fields so as to group the fields per result.
So views is displaying all the results as fields and I need to theme it as per each result. So each result will have the name, image ....
You can see the current results view here : http://www.iamvishal.com/dev/prosearch/%20/%20/%20/%20/%20
I tried to theme it using views-view-unformatted.tpl.php file but It won't do anything. I did change the tpl to suit my view such as views-view-unformatted--properityresults--page.tpl.php.
It won't work. Any clues what is going wrong ?
Below is the code:
<?php if (!empty($title)): ?>
<h3><?php print $title; ?></h3>
<?php endif; ?>
<?php foreach ($rows as $id => $row): ?>
<div class="<?php print $classes_array[$id]; ?>">
<?php print $row; ?>
</div>
<?php endforeach; ?>
The correct template file was views-view--properityresults--page.tpl.php
and not views-view-unformatted--properityresults--page.tpl.php.
cheers,
Vishal
I will mark is solved after a day as per the system settings.

Resources