ACF get the value of an options field in a plugin - wordpress

I am using the Advanced Custom Fields plugin with the options add on.How can I use the value of a field from options in a plugin?I have a simple php file in the plugins folder that needs to get this value. Is that possible?

For anyone searching for the solution:
Suppose your options field is a text field named "my_option_field_01".
In your php, if you wanted to display the value of that option field inside of a paragraph tag, you would put this:
<p><?php echo get_field('my_option_field_01', 'option'); ?></p>

Related

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);?>

Add php user input controller to wordpress customizer

Trying to customize the Wordpress Theme Customizer to allow users to input either a shortcode or a custom php string. Currently, I have many user input fields for text input, but I can't figure out how to sanitize the text correctly to allow for php.
Any suggestions on where to start?
Thank you user5552351 for your response.
After looking at the codex you referenced in your comment, I realized I was way over thinking the solution.
Turns out all I needed was to give the user a text input that allows for basic brackets [] and apostrophes '' while inside a do_shortcode function.
<?php echo do_shortcode(get_theme_mod( 'THEME_MOD_ID', 'THEME_MOD_DEFAULT_VALUE' ));?>
where THEME_MOD_ID is the identifier for the Theme Customizer Control. So Basically there's a section in my theme customizer called 'Contact' that holds a text input setting/control called 'custom_contact_form', where a user can input a shortcode (ex: [simple_contact_form] ) and it will replace everything between do_shortcode( + ). So my code might look something like this:
<?php echo do_shortcode(get_theme_mod( 'custom_contact_form', '' ));?>

WordPress Page Templates for Custom Post Type

I have a custom post type, "Store Pages" for instance, which is an almost identical duplicate of the default Wordpress "Page" post type.
Like the "page" post type, I would like to create page templates (not post-type templates) and be able to select them from the "Template" drop-down within the "Page attributes" box in the page editor.
I have created several templates, but the drop-down menu does not appear; I am assuming this is because a custom post types does not allow support for this.
Is there a way I can create page templates for a custom post type without using "single-{post-type-name}.php" and having a dozen queries to load up different template files?
I have double checked the comments for the templates are correct as they appear when I create a new page (post type, "Page").
Help would be greatly appreciated.
starting 4.7 you can use the new feature described here https://make.wordpress.org/core/2016/11/03/post-type-templates-in-4-7/
<?php
/*
Template Name: Full-width layout
Template Post Type: post, page, product
*/
// … your code here
If I understood correctly you want a Select template dropdown for your custom post type.
You can do this easily through Advanced Custom Fields, here's a quick guide how to get through.
After installing the plugin you can access the Custom Field section, if you open it and click Add new it bring you to the field editor. Name it whatever you want, it's just for administrative display.
On Field type choose "Select", this will allow you to construct a select box on your backend, keep in mind the value of "Field name" you will need this later on the code.
Scrolling down you can add the values of the select box in the following format: "key value : Textual label" just assume for now you want 2 templates, one for audio posts and one for video posts.
If you keep scrolling down you can see the display rule for this field group, now you will have "post" and "page" by default, when you add different content types you will have the additional content types here to select, just go ahead and pick yours.
And, ta-da. If you go on the custom content type edit window you will find your new fresh select box here waiting for you.
The code integration now is very simple, just go onto your single-{post-type-name}.php template and pull the custom field data into your loop. Then you can use this to use get_template_part() to pull your custom templates.
<?php $template_type = get_field('template'); // This must match with the field name value ?>
<?php if (isset($template_type) && !empty($template_type)): ?>
<?php get_template_part( 'store', $template_type ); ?>
<?php else: ?>
// You should have a fallback for the all the existing posts without template set or if you create a new post without a template.
<?php endif; ?>
In this specific example the pulled template files will be in the format of store-{key-value-of-the-selectbox}.php, of course you can readapt that for you best convenience.

How to get related type post id in magic field plugin

I am using magic field plugin for my project and created two related type fields and I want to get selected post/page id. Please help me I am stuck here.
Inside the loop you can say:
<?php echo get('field_name') ?>
Replace field_name with the name of your field. This should print it's contents.

Custom theming for content type in Drupal

I can apply a custom theme to a certain content type in Drupal by copying the node.tpl.php file and placing the name of my content type right after the "node" in the file name and appending an hyphen. Ok, the new name is: node-page_two_columns_images.tpl.php.
But that won't give me much flexibility if I am not able to edit the way each of the fields of my content type are rendered. If you get the node.tpl.php file, here is the line I am interested in:
<?php print $content ?>
I need to edit the way the elements in $content are rendered. Why? Basically because the title of the page needs to go between two of these elements... more or less like this:
<div id="field-1-of-my-content-type">[stuff1]</div>
<h1><?php print $title ?></h1>
<div id="field-2-of-my-content-type">[stuff2]</div>
Is there a template file I can create to replace the elements in this $content variable or do I need to write my own specific function?
Thank you!
check out the content template module.
Instead of using $content, you can print out all the elements yourself, as they are available in the node template. That way you can arrange the title and CCK they way you want to.
Update:
The easiest way to theme a node with CCK fields is to use $field_[field_name]_rendered, it has the themed version of the CCK field. CCK creates that variable to make theming the node easier.

Categories

Resources