We are using carbon field plugin for custom field in WordPress site but problem is that WordPress is not able to store revision for carbon custom filed. Please any one can help?
There are two way to include carbon field plugin in theme.
1) adding carbon field plugin in plugin folder and activate.
2) adding carbon field plugin folder in theme folder.
/* Integrating Carbon Fields Plugin */
use Carbon_Fields\Container;
use Carbon_Fields\Field;
add_action( 'after_setup_theme', 'crb_setup_theme' );
function crb_setup_theme() {
// check if Carbon Fields is not already installed
if ( ! class_exists( "\\Carbon_Fields\\Field\\Field" ) ) {
require( get_template_directory() . '/carbon-fields/carbon-fields-plugin.php' );
}
}
add_action('carbon_register_fields', 'crb_register_custom_fields');
function crb_register_custom_fields() {
require get_template_directory() . '/theme_option/meta_boxes.php';
}
In meta_boxes.php file you need to create metafield. like this
use Carbon_Fields\Container;
use Carbon_Fields\Field;
Container::make('post_meta', 'Date Container') // New Added
->show_on_post_type(array('hotel')) // Hotel is custom post type
->add_fields(array(
Field::make('complex','hotel_details_page_content', 'Images & Content')
->add_fields('Entry Container', array(
Field::make("separator", "crb_image_options", "Image Entry"),
Field::make("image", "row_images", "Image"),
Field::make("text", "row_image_headlines", "Image Headline"),
Field::make("text", "image_row_subheadlines", "Image Sub Headline"),
Field::make("separator", "crb_style_options", "Content Entry"),
Field::make("text", "content_titles", "Title"),
Field::make("rich_text", "content_datas", "Content"),
)),
));
Container::make('post_meta', 'Gallery Container')
->show_on_post_type('gallery') // Gallery is custom post type
->add_fields(array(
Field::make('complex','galleryimages', 'Gallery')
->add_fields('Gallery Entry', array(
Field::make("image", "gallery_images", "Upload Image"),
))
));
In this way you can create multiple fields as repeater and value also save.
and Get values on frontend.
$carbvalue= carbon_get_post_meta(get_the_ID(), 'hotel_details_page_content', 'complex');
foreach ($carbvalue as $carbonvalues) {
$herorimageid = $carbonvalues['row_images'];
$heroimage = wp_get_attachment_url($herorimageid);
?>
<img src="<?php echo $heroimage; ?>" sizes="100vw" alt="heroimage" />
<?php
echo $carbonvalues['row_image_headlines'];
}
Related
So i'm using Wordpress, Woocommerce and the "Product Video for WooCommerce" plugin by Addify. The URL to a mp4 video is stored in the:
wp_postmeta table
In this table, the post_id matches the product.
In the "meta_value" i can see the URL i've added.
No my question;
I want to place a download button that downloads the video stored in this location.
I've located the woocommerce hook where the button needs to come, but I can't figure out how to fetch the url from this meta_value.
My code skills are very basic so this is to complicated for me.
Can anyone help me out on this?
This showed me that the URL is visible but surely not the end goal :-)
add_filter( 'woocommerce_share', 'custom_button', 20 );
function custom_button() {
$meta = get_post_meta(get_the_ID(), '', true);
print_r($meta);
}
//Here I want to add the button
print '<button>Download video</button>';
Thanks!
'woocommerce_share' hook is an action, not filter.
Try this
add_action( 'woocommerce_share', 'custom_button', 20 );
function custom_button() {
$download_url = get_post_meta(get_the_ID(), 'afpv_cus_featured_video_id', true);
if ( empty( $download_url ) ) { // do not print anything if download_url doesn't exists
return;
}
// print the download button
printf( '<a href="%s" class="button" target="_blank" download>%s</a>',
esc_url( $download_url ),
__( 'Download video', 'text-domain' ) // string can be translated, change text-domain by the theme domain or plugin domain
);
}
I am trying to display a set of custom fields on WooCommerce Vendor pages via Advanced Custom Fields. For the base vendor functionality, I am using the following plugin: https://woocommerce.com/products/product-vendors/
I have added the custom fields under ACF Field Groups and set the display rules to "Taxonomy ยป Vendors". With this in place, the custom fields are displaying within each individual "Edit Vendor" dashboard.
Within the vendor plugin files I have found where I would like to display the custom fields, which is on line 210 of the file WooCommerce Product Vendors / includes / woocommerce-product-vendors/includes/class-wc-product-vendors-vendor-frontend.php
Initially I tried using the following basic ACF code to display the custom fields, to no avail:
<p id="sample"><?php the_field('field_name'); ?></p>
I have also tried saving the field as a variable and then displaying it, again to no avail:
<?php
$variable = get_field('field_name');
echo '<p>' . $variable . '</p>';
?>
In both of these examples, the <p> wrapping elements are showing up on the front end, but the custom fields/variables are not.
One interesting thing I found is that when I use ACF to create an additional options panel within the WordPress dashboard, I am then easily able to display these variables from the options panel within the vendor pages. Following is the functions.php code I use to create this options panel:
if( function_exists('acf_add_options_page') ) {
acf_add_options_page(array(
'page_title' => 'Additional Theme Options',
'menu_title' => 'Additional Theme Options',
'menu_slug' => 'additional-Theme-options',
'capability' => 'edit_posts',
'redirect' => false
));
}
And then within the plugin file referenced as above, if I insert the following script it displays the options panel fields perfectly:
<?php the_field('sample_option_field', 'option'); ?>
The problem with the options panel route is that these are then global, singular variables and not registered on a per-vendor basis.
Thanks!
Thanks Fresz, defining the terms worked perfectly. Following is the code I inserted into the plugin file to properly display the custom fields from the Vendor taxonomy:
// get the current taxonomy term
$term = get_queried_object();
// vars
$vendorphoto = get_field('vendor_secondary_photo', $term);
$street = get_field('vendor_street', $term);
$city = get_field('vendor_city', $term);
$state = get_field('vendor_state', $term);
$zip = get_field('vendor_zip', $term);
echo '<img src="'.$vendorphoto.'">';
echo '<p id="sample">'.$street. "<br />" .$city. ", " .$state. " " .$zip.'</p>';
What I Have done until now, I am creating a WordPress plugin to add menu page for the document management in WordPress
<?php
/**
*
*
*
* #wordpress-plugin
* Plugin Name: doc management
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
/** Step 2 (from text above). */
add_action( 'admin_menu', 'my_plugin_menu' );
/** Step 1. */
function my_plugin_menu() {
add_menu_page( 'My Plugin Options', 'docs Management', 'manage_options', 'my_unique_identifier2', 'my_plugin_options','',4 );
}
/** Step 3. */
function my_plugin_options() {
if ( !current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
}
$file = plugin_dir_path( __FILE__ ) . 'view/main.php';
include_once $file;
}
?>
but I need to add functionality just like in WordPress Post and pages menu. So I am thinking instead of creating a new plugin for the functionality can I do it with custom post type. instead of adding pages or post I just want to add a document. that it's nothing else means instead of adding a new page. add a new document and list all those documents. bulk delete and all.
Is there any specific need that you are trying to build a custom plugin?
I recommend, you may try using https://wordpress.org/plugins/custom-post-type-ui/
I'm trying to find a way to choose a date and display it into a Wordpress page.
Simply put, that's the way this may operate:
One or several pages are input a shortcode or a PHP code via PHP insert
An operator/webmaster chooses a date from let's say a calendar or drop down
This date (formatted) shows into the pages that have the shortcode/PHP code
I do not want automatic or current date which I can do with this plugin.
Can anybody help achieve this with a plugin or a PHP snippet?
Display a custom date field in Settings->Reading:
function wpse_52414489_custom_date() {
// Add the section to reading settings so we can add our
// fields to it
add_settings_section(
'eg_custom_settings',
'My custom settings',
'',
'reading'
);
// Add the field with the names and function to use for our new
// settings, put it in our new section
add_settings_field(
'eg_custom_date',
'My custom date',
'eg_custom_date_callback',
'reading',
'eg_custom_settings'
);
// Register our setting so that $_POST handling is done for us and
// our callback function just has to echo the <input>
register_setting( 'reading', 'eg_custom_date' );
}
function eg_custom_date_callback() {
echo '<input name="eg_custom_date" id="eg_custom_date" type="date" value="' . get_option( 'eg_custom_date' ) . '" class="code" /> Explanation text';
}
add_action( 'admin_init', 'wpse_52414489_custom_date' );
Add your shortcode (EDIT: custom date format):
add_filter( 'init', function() {
add_shortcode( 'my-custom-date', function() {
return date( 'd/m/Y', strtotime( get_option( 'eg_custom_date' ) ) );
});
});
Usage:
[my-custom-date]
Output:
2018-09-18
I am using Wordpress and the Genesis framework for a site. I'm using a child theme (Ayoshop - not that it matters much) for the theme. I would like to customize the search results page by removing the 'post info' area where it shows the date, author, and 'leave a comment' link, and instead show the featured image for that post. The theme is using the search.php page from the Genesis theme, so I'm not really sure how to proceed in how to customize it.
Here is the code from the Genesis theme search.php:
add_action( 'genesis_before_loop', 'genesis_do_search_title' );
/**
* Echo the title with the search term.
*
* #since 1.9.0
*/
function genesis_do_search_title() {
$title = sprintf( '<div class="archive-description"><h1 class="archive-title">%s %s</h1></div>', apply_filters( 'genesis_search_title_text', __( 'Search Results for:', 'genesis' ) ), get_search_query() );
echo apply_filters( 'genesis_search_title_output', $title ) . "\n";
}
genesis();
It actually did matter that it was the Ayoshop theme, there was a custom filter that was added in a file called theme-tweaks.php that removed the original post info and added a custom post info, so I needed to remove that custom action.
All of the changes were done in the functions.php file.
I made sure to remove the genesis_post_info, and then removed the custom action that Ayoshop added.
remove_action( 'genesis_before_post_content', 'genesis_post_info' );
remove_action( 'genesis_before_post_content', 'ayo_post_info' );
I then added an action to add the image to the post.
add_action ( 'genesis_before_post_content', 'jl_post_info' );
function jl_post_info()
if ( has_post_thumbnail() ) {
printf( '<div class="post-info">' . get_the_post_thumbnail() . '</div>');
}
}