Conditionally including JS based on whether ACF field is set [closed]

The Loop isn’t available yet in wp_enqueue_scripts, so is_single() etc pp aren’t going to work. However, the queried object has already been determined, so you could use something like add_action(“wp_enqueue_scripts”, function() { $qo = get_queried_object(); if(get_class($qo) == “WP_Post”) { if($val = get_field(“my-field”, $qo->ID)) { wp_enqueue_script(“jquery”); } } });

ACF Load Field Groups Programmatically [closed]

In case anyone needs it, this is working for my needs: add_filter(‘acf/get_field_group’, ‘my_change_field_group’); function my_change_field_group($group) { $get_current_screen = get_current_screen(); $get_current_post_type = $get_current_screen->post_type; $my_option = get_field(‘my-option’,’option’); if ( $get_current_post_type == ‘my-cpt’ && $my_option == ‘stuff’ && $group[‘key’] == ‘group_123456789’ ) { $group[‘location’] = array( array( array( ‘param’ => ‘post_type’, ‘operator’ => ‘==’, ‘value’ => ‘my-cpt’, ), … Read more

Filter posts by multiple checkbox categories

I thing, you should use this code for filter the check box category <?php // cat 42=Laos cat 57=2-4Days <?php $my_query_1 = new WP_query(array(‘category__and’ => array(42,57))); ?> <?php while ($my_query_1->have_posts()) : $my_query_1->the_post(); ?> <a href=”https://wordpress.stackexchange.com/questions/100169/<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”><?php the_title(); ?><?php the_excerpt(); ?></a> <?php endwhile; ?>

How to create a list of terms who’s posts also have a predefined external term?

if i understand correctly you want to get a list of albums (posts) of a specific artist(taxonomy) and that are have ihaveit term. if so the its a simple query using tax_query: $args = array( ‘posts_per_page’ => -1, //get all ‘post_type’ => ‘album’, ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘artist’, ‘field’ => … Read more

Joining tables not working in the post editor page

The easy way in the admin is to do a 2nd custom query using the post_id from the post object. function custom_posts_data( $posts, $query ) { global $wpdb; if ( !count( $posts ) ) return $posts; while ( $posts as $post ) { $query = “SELECT * FROM {$wpdb->prefix}my_plugin_table WHERE post_id={$post->ID}”; $results = $wpdb->get_results( $query … Read more