Wordpress CPT UI and ACF custom fields - wordpress

i am using CPT UI for custom post type and ACF custom fields.
i have created custom post type (companies) and linked to its custom fields. In admin everything is okay. I want to display this in front end. The user can be enter the company details also. How can i display this in front end ?

<?php
$id = get_the_ID();
$data = get_field('custom_field_name', $id);
echo $data;
?>
Obviously this will need a lot of refinement to look good but that's the basics on how to retrieve data from an ACF field. You may need to var_dump($data); in order to figure out how to get the part you want (if it's not just storing a string). Without more details on what you're doing that's a good an answer as I can give you.

Related

How to add custom fields in invoice and wordpress backend?

I am working on a wocommerce website, and i want to display a tax that will be custom calculated eg: (weight0.660+price=taxquantity) i am using this formula for custom fields calculation. now i want to display the calculated output on user invoice when user checks out. please help me with this
I am using ACF pro plugin to create custom fields and add custom formula.
You need to find the template for the invoice and add
<?php echo get_field('fieldname', $id); ?>
fieldname will be the name of the ACF field and $id will need to be the post id for wherever the field is

Can we replicate ACF functionality in our theme?

Hi i want to add advance custom fields in my wordpress theme. I don't need editor functionality but to provide the users the facility to enter the values to view in the frontend.
basically i want to add the custom fields in my theme just like ACF but i don't want to use the plugin. Is there anything anyone can help me out with this please do.
I'm using ACF plugin right now to add custom fields in my theme.
For example I'm getting the designation from user in the admin panel and our team members custom post type. and showing it on the home page by using this code.
<p><span class="fa fa-user-circle"></span> Designation</strong>:<?php echo the_field( 'designation' ); ?> </p>
I don't want to use ACF plugin to perform this task. I know about the wordpress custom field. The problem with wordpress custom field is I've to select the key every time when I create a post. Here's a sample of what I'm trying to do. I want to add the this in my add new post.
Right now I've to select the key value whenever a new post is created. I want something similar to the image attached in my add new post. Thanks.
You can use native WordPress function(s) to do the same thing. Of course, you lose the extensive ACF features and slick ACF admin panels.
Instead of using ACF's get_field(), you can use get_post_meta(get_the_ID(), 'field', true);
List all items in the meta field 'appartments' like so:
$meta_name = 'appartments';
$fields = get_post_meta( $post->ID, $meta_name, true );
foreach ( $fields as $fieldValue )
{
echo $fieldValue . ' ';
}

advanced-custom-fields the_field function not work in wordpress

I'm trying to use the the_field(); function in wordpress but did't work
also I tried to use the get_field(); function and same problem what I can do
<?php the_field('contact_form_short_code'); ?>
I am using advanced-custom-fields plugin the free version
the_field('contact_form_short_code') will try to get the field info from the current post in the loop. If you're not currently in a loop it will look to the current page/post.
If you want to reference a post from outside the loop you must specify the post ID, eg: the_field('contact_form_short_code', $post_id)
Hope that helps
Check if your field group location points to your template, taxonomy or custom post type, after that try to use echo to call your field.
Check this link www.advancedcustomfields.com
If you want to display the shortcode (contact_form_short_code) specified in the admin panel via a custom field (ACF), you need to use the do_shortcode(); function.
In your case, the code looks like this:
<?php
//In the admin panel we fill the shortcode of the contact form, for example CF7.
//[contact-form-7 id="1" title="Form"]
$cform = get_field('contact_form_short_code', $post_id);
//Output of shortcode
echo do_shortcode($cform);?>

Dropdown of existing posts in a metabox

I want to have ability to choose for each page what post should appear in a sidebar, from multiple posts type. So I understand that I need a meta box with a dropdown list of all posts, but I don't know how to build this in functions.
I only found this solution which is quite similar to what I want, but this doesn't help me to much, because I can only choose from a single post type and display only in post pages.
There is a free plugin that will solve all of your woes. It's called ACF or Advanced Custom Fields. It has the ability to add a list of posts to a field and attach that field to pages. Here's how you'd do it:
First install the plugin and navigate to the custom fields screen. Setup your field exactly like this:
Then in the options below that section you need to select these options:
That will tell ACF to put the field only on pages. After you have set that up you will get a little sidebar block like this:
You can then select each post for the page and it will return that object on the frontend. You do need to use a little code to get the frontend to spit out the posts you need. Here is the code to get a frontend option from ACF. Inside of the sidebar.php file you need to add this code:
global $post; // Get the global post object
$sidebar_posts = get_field('posts', $post->ID); // Get the field using the post ID
foreach($sidebar_posts as $sidebar_post){ // Loop through posts
echo $sidebar_post->post_title; // Echo the post title
}
This will simply loop through the posts you select and echo out the title. You can do more with this by adding some other Wordpress post functions using setup_postdata(). This will allow you to do things like the_title() and the_content().
Hope this helps!

Create a blog post from content in another post type

The Wordpress site I'm working on has a section for "News" (which is the regular blog/posts) which will be used for any news the company has to write about. Then I have a custom post type for Promotions, which has it's own page.
I want the client to be able to add his promotion content through the custom post type, which is going on the Promotions page, however I'd like this content to also be "cross posted" into the blog/news without forcing the client to write it up twice.
Is there a way to do this? Thanks.
Just a note: The reason I have the promotions as a custom type on it's own instead of just having them do it all from the blog is because I needed custom fields that would be unnecessary for any other kind of blog post.
Two options:
1) Use the Shortcode API
And in your cross-post you'd add the shortcode [crosspost id="POST-ID"]. Where POST-ID corresponds to the numeric ID of the other post (post type). Instead of ID, the title could be used, see the function get_page_by_title.
Create your own plugin for this. Add a sample shortcode from the Codex and use the function get_post to get the contents of the cross-post.
2) Use Advanced Custom Fields plugin
With it, adding meta boxes with custom fields is a breeze. And it has a Post Object field that's basically a Cross Post functionality.
You could do it a lot more simply by adding a filter to wp_insert_data(). For example, in your theme's functions.php file add the following:
add_filter('wp_insert_post_data', 'post_to_other', 99, 2);
That filter will then run anytime you add a new post. In the function post_to_other(), you look to see what type of post is being submitted. If it's a promotion, then insert a second copy as a News item.
function post_to_other($post_id, $post){
/** check $post to see what type it is, if it's a promotion */
if($post->post_type == 'promotion'){
$second_post = array(
'post_type'=> 'post',
'post_title'=> $post->post_title,
'post_name' =>$post->post_name,
'post_content'=> $post->post_content,
'post_author'=> $post->post_author,
'post_status'=> 'publish',
'tax_input'=> array('taxonomy_name'=>array('news'))
);
wp_insert_post($second_post);
}
}
I'm running out the door so I don't have time to double check the exact code but that's the basic structure of it. The tax_input bit is optional, lets you specify a category if you want. You'll probably need to tweak it a bit but that's the basics.

Resources