Support

Account

Forum Replies Created

  • Hi John, I must have missed the email alert when you replied to this, so apologies for my delayed response.

    In the end I didn’t use a new field type for the Page Builder side of the project, I used a combination of Flex and Repeaters utilising cloned Field Groups, which coupled with some custom js has worked well. I think your right and it is possible but for the scope of the project it would be too time consuming to work out, and as I’ve managed to achieve it with the built in ACF functionality, ultimately not worth it at the moment…

    Like you however I’m keen to try it properly at some point, so I’ll let you know how I get on.

    I have, however created a new field type to handle options/styles, however it is has turned into a bit of an unwieldy beast. I’m essentially providing settings for margin, padding, background image/colours/gradients and typography. Different sections are enabled in the Field Settings so it can be used for Rows, Columns or the actual content blocks. I feel it does need to be it’s own field type as I’m using quite a bit of custom js and css to control the UI.

    The problem is it takes an age to load especially when there are lots of Field Groups that use it. I’ve narrowed the load time issue to the actual render_field( $field ) function, which contains quite a bit code. So now I’m wondering if it’s possible to use AJAX to trigger the rendering of the field when a button is clicked rather than have each render on page load.

  • Sorry just re-read your question. You need to get the number of posts with a difficulty of Easy, Average & Difficult for each term right?

    You’ll need a custom wp_query with a tax_query and a meta_query.. Something like the below will get you the post count for Easy Chocolate Deserts..

    
    $args = array(
    	'post_type'  => 'recipes',
    	'tax_query' => array(
    		array(
    			'taxonomy' => 'desserts',
    			'field'    => 'slug',
    			'terms'    => 'chocolate',
    		),
    	),
    	'meta_query' => array(
    		array(
    			'key'     => 'difficulty',
    			'value'   => 'Easy',
    			'compare' => 'IN',
    		),
    	),
    );
    $easy_choc_query = new WP_Query( $args );
    
    echo $easy_choc_query->found_posts;
    

    More info from the Codex

    To make it more dynamic we’d need to see your html structure. You’d possibly need to put something like the above inside the get_terms foreach loop, swapping out ‘chocolate’ and ‘easy’ for variables that changed with each iteration.

  • You can use get_terms, then term->count..

    The below will list all the terms from the Desserts taxonomy with their name and post count.

    <?php   
    $terms = get_terms( 'desserts' );
    if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
        echo '<ul>';
        foreach ( $terms as $term ) {
            echo '<li>' . $term->name . ' - ' . $term->count . '</li>';
        }
        echo '</ul>';
    }
    ?>
    

    For more info check – HERE

  • Thanks again John. I had a feeling it might be quite complex..

    One the real pros for being able to create new field types is the ability to control the html structure and js functionality of the edit screen. Unfortunately it does seem that using the Repeaters & Flex fields inside a new field type will be rather complicated…

    I’m actually building a Page Builder, I’m more or less there with a proof of concept, but being able to use Repeaters & Flex within the various new field types would make things so much easier and cleaner.

    I’ll give it a go.

  • Thanks John, that’s really useful – great add-on too.

    Not sure that sorts my issue out though, I want whoever is editing the post to be able add/remove rows/inputs when editing the posts themselves.

Viewing 5 posts - 1 through 5 (of 5 total)