How do I echo a Wordpress plug in short code that I will be putting in the Custom Meta field in the post I have called Treatment 1?
Short code is
[table id=6 /]
My php which I cant work is
<?php
$post_meta = get_post_meta($post->ID, "Treatment Right 1", true);
if (!empty($post_meta)) {
?>
<?php echo do_shortcode($post_meta;); ?>
<?php
}
?>
Please help
<?php echo do_shortcode($post_meta); ?>
You have a semi colon inside your shortcode function for a start.
not 100% sure what you are trying to achieve.
Does the custom meta field just contain the name of the shortcode or the full string?
i.e. does it include the square brackets [shortcode] rather than just returning 'shortcode'
you could try:
echo do_shortcode('['.$post_meta.']');
have you written the shortcode function of 'table' yourself?
Related
I'm trying to output the inout from a subfield of a group in AFC.
With a regular textfield I just use:
<?php $ups4 = get_field('ups_four', 'option'); ?>
</a <?php echo $ups4; ?></a>
Which is simple enough, but I fail to do this with a subfield. I've tried to go through examples but nothing works.
The type group name is header_usps and the subfield name usp_1.
How do I echo the subfield in an element?
You can simply try it like this (Not sure what exactly you were trying to achieve with the <a> tag, but it was broken, so I fixed that as well):
<?php $ups4 = get_field('header_usps_usp_1', 'option'); ?>
<?php echo $ups4; ?>
I'm using Coupon Creator and I like that it comes with the categories and shortcodes. I am using a category shortcode like this example [coupon couponid="loop" category="Brumby's Bakery" couponorderby="date" coupon_align="cctor_alignnone" name="Coupon Loop"].
I wanted to use different category shortcode for each page. Therefore, I kinda created a custom meta box for that (Wordpress Meta Boxes) and called it in the php template page with <?php echo get_post_meta($post->ID, 'couponshortcode', true); ?>. However, the shortcode won't work in php template page unless I use <?php echo do_shortcode('[coupon...]'); ?>
In the end this code which was supposed to be like that wouldn't work because of php in php.
<?php echo do_shortcode(<?php echo get_post_meta($post->ID, 'couponshortcode', true); ?>); ?>
How do I rework this php code? The only thing I could think of is to use something like var but I don't know how to make it work in php template page.
var $store = <?php echo get_post_meta($post->ID, 'couponshortcode', true); ?>
<?php echo do_shortcode($store); ?>
No need to echo get_post_meta(). This should work:
<?php echo do_shortcode(get_post_meta($post->ID, 'couponshortcode', true)); ?>
I have Woocommerce outputting get_categories and get_tags in the example below, but need them to be text only. At present, it outputs text with a link to the category / tag. Can the link component be removed?
<?php echo $child_product['product']->get_categories(); ?>
<?php echo $child_product['product']->get_tags(); ?>
Thank you.
In case anyone else was looking for a solution to this...
<?php echo strip_tags ($child_product['product']->get_categories()); ?>
I'm not very familiar with PHP and have been trying my hardest to figure out how to create this URL. So far, this is working:
<?php echo site_url($p->post_title) ?>
Where post title is defined by the Mapify.it Wordpress plugin. The result is:
http://siteurl.com/post_title
What I'd like to do is add a string before it, ideally ?s= or /search/, but when I try to add this before $p->post_title I'm still generating the above URL. Variations such as:
<?php echo site_url('?s=', $p->post_title) ?>
<?php echo site_url('/search/', $p->post_title) ?>
produce http://siteurl.com/?s= and ignore the variable. Nothing seems to do what I want.
What am I doing wrong?
Hope you need the following url format,
http://siteurl.com/?s=Here come the post title
So,
<?php echo site_url("?s=".$p->post_title) ?>
OR
<?php echo site_url("/search/".$p->post_title) ?>
should work.
Found it!
<?php echo site_url('?s='), $p->post_title ?>
Instead of adding custom URL Parameters directly, I'd suggest you to use WordPress built-in function add_query_arg(), it's more cleaner.
Here is an usage example:
$url = get_site_url();
$params = array(
's' => $p->post_title
);
echo add_query_arg($params, $url);
You can specify multiple parameters this way.
For ref: Check add_query_arg()
I am using wordpress get post meta to store the value of a custom field into a variable. In this particular instance, It is actually grabbing the post's parent's custom field due to the $post->post_parent Here is the code:
<?php $cast_members = get_post_meta($post->post_parent, 'cast_members', true); ?>
<p><?php echo $cast_members; ?></p>
<?php endif; ?>
The custom field cast_members is a series of cast members, each in its own paragraph. For some reason wordpress is stripping out the paragraph tags and displaying all of the cast members in a continuous string. I need to retain those paragraph tags so each cast member is on its own line. Any idea why get_post_meta strips out tags and how to fix it?
Why not do something like this,
<?php
$mykey_values = get_post_custom_values('cast_members',$post->post_parent);
foreach ( $mykey_values as $key => $value ) {
echo "</p>". $value ."</p>";
}
?>
Or you ca use your original query but just add a foreach to echo out the value wrapped in <p> tags.
Thanks to #Vinod Dalvi the answer involves using wpautop like so:
<p><?php echo wpautop($cast_members); ?></p>