17 votes
Accepted

Unable to check if plugin is active

Try to check class_exists: <?php if( class_exists('acf') ) { echo "hi"; } ?>
Behzad's user avatar
  • 466
14 votes
Accepted

Filter by custom field in custom post type on admin page

And for displaying result for Filter then try this code add_filter( 'parse_query', 'prefix_parse_filter' ); function prefix_parse_filter($query) { global $pagenow; $current_page = isset( $_GET['...
Aftab's user avatar
  • 1,226
14 votes
Accepted

Is it possible to add custom fields to a WooCommerce attribute term?

Yes, it is possible. And there's an easy guide here. Below is a working code you can add to the theme's main functions.php file: // Adds a custom rule type. add_filter( 'acf/location/rule_types', ...
Sally CJ's user avatar
  • 36k
13 votes
Accepted

How to add a custom field to quick edit

There are a few steps to create the custom quick edit box and custom column create a custom meta key (assumed that you have 1 already) add custom admin column title and data (assumed that you want to ...
西門 正 Code Guy's user avatar
12 votes
Accepted

Display List Of Posts Containing a Relationship Field Value [ACF]

I am updating my complete answer based on your clarification in the comment below. I hope this helps: <div class="entry-content"> <h2>Documents written by this writer</h2> ...
Prasad Nevase's user avatar
11 votes

Filter by custom field in custom post type on admin page

The restrict_manage_posts action triggers the add_extra_tablenav() function, which is how you add additional dropdowns to your desired List Table. In the example below, we first ensure that the Post ...
David Gard's user avatar
  • 3,260
11 votes

Visual Composer vs. Advanced Custom Fields

Tell your boss that Visual Composer is the cancer of WordPress. Tell your boss that you've separated content concerns from visual ones, and that you're not tied into an abhorrent shortcode nightmare ...
TheDeadMedic's user avatar
  • 36.1k
10 votes

Order get_terms using a Custom Field

A much shorter solution, just add this before foreach: usort($terms, function($a, $b) { return get_field('issue_date', $a) - get_field('issue_date', $b); });
Grigur's user avatar
  • 201
10 votes
Accepted

Media library - Limit images to custom post type

I'm not 100% sure if I get your problem right, but... Maybe this will help you... Media uploader gets attachments with simple WP_Query, so you can use many filters to modify it's contents. The only ...
Krzysiek Dróżdż's user avatar
9 votes

Matching Serialized Arrays with meta_query

I just figured out myself how to do it Take a look at this example: $args = array(); $args['relation'] = 'OR'; foreach ( $tag_ids as $t ) { $args[] = array( 'key' => '...
e4rthdog's user avatar
  • 441
9 votes
Accepted

Add custom field to the archive page?

Using the Advanced Custom Fields plugin you can assign options pages to you custom posttype like this: if( function_exists('acf_add_options_page') ) { acf_add_options_page(array( '...
Luckyfella's user avatar
8 votes

ACF - get fields from group

I'm surprised no one mentioned acf_get_fields('someGroupId') yet. /** * acf_get_fields * * Returns and array of fields for the given $parent. * * @date 30/09/13 * @since 5.0.0 * * @param ...
Lucas Bustamante's user avatar
8 votes
Accepted

importing third party json feed as custom post type

If you want the D.I.Y. route... The post type in this example is set to 'post' but you can see where to change it. Here is a working example to pull the data ( first page in this example ), parse the ...
jgraup's user avatar
  • 9,629
8 votes
Accepted

How to get "Additional CSS Class" for ACF Gutenberg block

Note that I don't have ACF PRO 5.8 which comes with the Block features, but I hope this answer helps. If you look at the example here, you can retrieve the additional/custom CSS classes using props....
Sally CJ's user avatar
  • 36k
7 votes

Unable to check if plugin is active

is_plugin_active() only available inside the admin area. You need to include the core plugin.php file in front end to use this function. From WordPress documentation NOTE: defined in wp-admin/...
Sumit's user avatar
  • 4,754
7 votes
Accepted

Remove Category description textarea

/*remove term descriptions from post editor */ function wpse_hide_cat_descr() { ?> <style type="text/css"> .term-description-wrap { display: none; } </...
CK MacLeod's user avatar
  • 1,838
7 votes
Accepted

ACF Repeater loops and resets - where is the reset_rows() documentation?

It's not in the documentation mainly because it's an internal function, they weren't expecting you to use or need it. have_rows() checks to see whether there is a currently active loop- if not, it ...
Steven's user avatar
  • 136
6 votes

Order and group posts by acf by month and year

When you query the posts with orderby argument as a event_date (it could be any field with date format) the posts are ordered by date, desc or asc. So the only thing you have to do afterwards is to ...
Laxmana's user avatar
  • 1,332
6 votes
Accepted

How to update custom taxonomy meta using ACF update_field() function or any other wordpress function

I figured it out somehow.. Syntax of update_field(): update_field($field_key, $value, $post_id) MY MISTAKE: I was using the wrong parameter for the $post_id which i thought was the Term Id of the ...
Seen Dru's user avatar
6 votes

Filtering multiple custom fields with WP REST API 2

This solution works with get_items() in /lib/endpoints/class-wp-rest-posts-controller.php of the v2 WP Rest API. First, you'll want to construct the GET arguments like you would for a new WP_Query(). ...
jgraup's user avatar
  • 9,629
6 votes

functions.php inject inline css

The easiest way I've seen is to echo it where you need it: function inline_css() { echo "<style>html{background-color:#001337}</style>"; } add_action( 'wp_head', 'inline_css', ...
vhs's user avatar
  • 310
6 votes
Accepted

ACF add custom fields to categories and display

Check this page out from the ACF docs: https://www.advancedcustomfields.com/resources/get-values-from-a-taxonomy-term/ Specifically this section: "Finding the term related to the current post" <?...
Bryan's user avatar
  • 76
6 votes
Accepted

ACF datepicker meta_query Compare Dates in m/d/Y g:i a - Not in Ymd Format

There should not be any need to do this. Even if an ACF Field is using 'return_format' => 'm/d/Y g:i a', The post_meta value is in YYYY-MM-DD 00:00:00 format. $date_now = date('Y-m-d'); $args = [...
admcfajn's user avatar
  • 1,266
6 votes

Using ACF to display data on all pages

As other users mention to create global options you need to have ACF Options Page add-on or ACF PRO. This will give you possibility to create nice options page and retrive your field in standard way: ...
kierzniak's user avatar
  • 2,412
6 votes
Accepted

Using Advanced Custom Field (ACF) to insert meta description on each page

As mentioned in the comments, you are outside of the loop, so get_field will not know the ID. You can use the code below: <?php $meta_description = get_field('meta_description', ...
Alexander Holsgrove's user avatar
6 votes
Accepted

How to store ACF custom fields data in a custom table

It is possible to save ACF data in custom tables by using a separate paid plugin called ACF Custom Database Tables. However, if your goal is just to keep the database as light as possible, meevly.com'...
WebElaine's user avatar
  • 9,193
5 votes

ACF: get_field() returning false

You need to pass in the ID of the post you're trying to get the field from: Eg get_field('display_featured_image', $post_id). In a loop you could do get_field('display_featured_image', ...
Hybrid Web Dev's user avatar
5 votes

get_field not displaying my custom field value

Nevermind, I figured this out. The id needs to be "category_" and then the ID. So the code is: $sub_heading = get_field("sub_heading", "category_" . $cat->term_id);
21zna9's user avatar
  • 371
5 votes
Accepted

Adding a body class with ACF

Hook into the body_class filter and add your field there. It might be better to get the ID from get_queried_object_id() instead of get_the_ID(). add_filter( 'body_class', 'wpse_20160118__body_class' )...
jgraup's user avatar
  • 9,629
5 votes
Accepted

If Custom Field is empty don't display div

Try this: <?php $business_services = get_field( "services_for_businesses" ); //etc... ?> <div class="section-title">Services for Individuals</div> <div class="...
Adam's user avatar
  • 16.3k

Only top scored, non community-wiki answers of a minimum length are eligible