Advanced Custom Fields inside a plugin - wordpress

I'm having some problems receiving data from the ACF plugin inside a plugin.
I'm using owl carousel to display a slideshow but i would like to add some extra text fields per image.
I created 2 caption fields in ACF and linked them to the post type of Owl Carousel.
implemented the fields inside the Owl Carousel main php file like so:
$caption1 = get_field('owl_caption1');
$caption2 = get_field('owl_caption2');
$loop = new WP_Query($args);
while ($loop->have_posts()) {
$loop->the_post();
$the_url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), $type);
$result .='<div class="item"><img title="' . get_the_title() . '" src="' . $the_url[0] . '" alt="' . get_the_title() . '"/><p>'.$caption1.'</p><p>'.$caption2.'</p></div>';
I also added the include line to the top of this document (plugins/owl-carousel/owlcarousel.php) to receive the date but when i fill in the fields they are not displaying
include_once('advanced-custom-fields/acf.php' );
The Faq of ACF states that you need to include the files inside your theme (themes/themename/advanced-custom-fields) or plugin (plugins/owl-carousel/advanced-customfields) so i tried copying the acf folder to my theme folder and the Owl Carousel plugin folder but i can't seem to receive the data.
Thanks in advance!

Related

Displaying ACF Custom Field in WooCommerce Vendor Pages

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>';

Trying to add an ACF field under the post title in Wordpress

My client is using the Divi builder theme and has asked me to insert a subhead under the post title on category archive pages. The theme uses the_content() to pull all content into the pages so simply adding a line under the title in the page templates isn't an option.
This may not be the best way to do it, but I used ACF to add get_field( "region" ) and modified the code from this github. It's inserting the field where I need it, but the title is reading html as text. I have a <br/> in there now but would like to replace with <span class="">. Any idea why it's not being read as code?
live example >
Code:
function gp121028_filter_title( $title ) {
$substrings = explode( ' | ', $title );
$title = ( ! empty( $substrings[0] ) ) ? $substrings[0] . '<br/>' . get_field( "region" ) : $title;
return $title;
}
Wasnt able to solve it - built it manualy.

woocommerce show the categories image on the page

im solving this for two days is there anyone there to help me. Im using Tweenty thirteen themes for wordpress customize it and i install the category listing plugins to show the image category but it sems on the side bar is no problem but in the content is showing this "Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\barfly\wp-content\plugins\woocommerce-category-widget\woocommerce-category-widget.php on line 445
"
Which version of woocommerce and wordpress are you using? Woocommerce are now on 2.3 and they under went lot of changes. Its not just about the foreach loop, even if you solved it, it would still need other changes.
What i would suggest is update woocommerce, wordpress and your listing plugin to the latest version. Secondly it looks like the category listing plugin you are using doesnot support the new version of woocommerce, Make sure it supports the latest version of woocommerce.
EDIT:
place this code within the loop, it will get thumbnail from the category and display them after the Category title.
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );
if ( $image ) {
echo '<img src="' . $image . '" alt="" />';
}

View attachment thumbnail of each post in a category list in Wordpress

this is what i would like to do...
In my site,each post can have several pictures, but also each post has an attached picture called: thumbnail {name of my post}, this specific picture was attached to the post with the multimedia gallery, and the objective of this picture is to appear in the category list.
<article>
<p class="the-picture"><img src="url-of-the-picture" /></a>
<p class="the-post-title">The post title</p>
<p class="the-post-excerpt">The post excerpt</p>
</article>
So basically that's what i want to do, Maybe using get_post() but i can't figure out how to do it from outside the post.
Thanks for your help
Consider using the defaul post thumbnails functions instead of naming the image after the post.
Add this to your functions.php
add_theme_support( 'post-thumbnails' );
Then on the editor you'll be able to select which image is the default "featured" image. To display the images on the loop you'll use either the_post_thumbnail() or get_the_post_thumbnail() like this:
<p class="the-picture"><?php the_post_thumbnail(); ?></p>
EDIT:
if you can't use the default thumbs functionalilty, maybe you can create another post field with add_meta_box(); and include it in every post save with update_post_meta();.
This way you'll have a permanent value on your DB to tell you which thumb to use on the cat list, and you'll be able to retrieve it with get_post_meta() on category.php like this:
<p class="the-picture"><?php echo get_post_meta($post->ID, $cat_picture, true); ?></p>
Ok... here is what I found so far:
The following code will get me the category i'm on:
global $wp_query;
global $wpdb;
$cat = get_category( get_query_var( 'cat' ) );
So, now with the category i can list all the posts:
$posts = get_posts( array( 'category' => $_GET[ 'cat' ] ) );
And for each post i can do this:
$attachment_id = $wpdb->get_var('
SELECT ID
FROM ' . $wpdb->posts . '
WHERE post_parent = "' . $record->ID . '" AND post_status = "inherit" AND post_type="attachment" AND post_title LIKE "thumb%"
ORDER BY post_date DESC
LIMIT 1');
$thumb = wp_get_attachment_image_src( $attachment_id, array( 90, 117 ) );
$the_icon = '<img src="' . $thumb[0] . '" width="' . $thumb[1] . '" height="' . $thumb[2] . '" />';
So, basically what i'm doing is looking for the ID of the child post which is marked as the thumbnail of the post and retrieving its information into $thumb. The answer that moraleida gave me was a nice start for my research. Thanks a lot.

Best way to add two row list for CMS (wordpress)

What is the best way for me to add a two row list with employees to a Wordpress CMS?
Like this: live example
| picture | personal data |
In the example above I've used a table, but this would properly work better created as CSS.
I need a way for the client to add new employees without writing ANY code. I've considered using the image caption (but I can't style it the way I want) or create a list UL - LI
I've also looked at some table plugins, but it isn't exactly working as I need. Perhaps I need to write such a plugin?
Any ideas as to how I can solve this problem?
I've solved the problem :-D
I simply have to add new user profiles as 'subscriber' and install the 'user photo' plugin. Then I can display the user data the way I want.
This is what I ended up using:
<div class="personale_table">
<?php
$wp_user_search = $wpdb->get_results("SELECT ID, display_name FROM $wpdb->users ORDER BY ID");
foreach ( $wp_user_search as $userid ) {
$user_id = (int) $userid->ID;
$user_login = stripslashes($userid->user_login);
$display_name = stripslashes($userid->display_name);
$user_info = get_userdata($user_id);
?>
<?php
echo('<div class="personale_thumb personale_ramme">' . get_avatar($user_id) . '</div>');
echo('<div class="personale_data"><div class="personale_linje personale_title">' . $user_info->first_name . ' ' . $user_info->last_name . '</div>');
echo('<div class="personale_linje personale_stilling">' . $user_info->aim . '</div><div class="personale_linje">' . $user_info->yim. '</div><div class="personale_linje">' . $user_info->user_email . '</div><div class="personale_linje">' . $user_info->jabber . '</div></div>');
}
?>
</div>

Resources