Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • If you need to show each row of a repeater as it’s own page I would suggest that you use a custom post type instead.

    Is is possible? I was able to do what you are looking for by creating links to pages the way WP does for paged content. I started here http://www.wpbeginner.com/wp-tutorials/how-to-split-wordpress-posts-into-multiple-pages/

    I build my own function that created the links that were necessary and then in the content of the template I read the query string and figured out what row of the repeater I was supposed to be showing and then got that row and displayed it.

    If I had it to do over again I would have used a hierarchical custom post type with one parent and multiple child posts.

  • Did that sort out your question?

  • Are you trying to get all of the values from all users or just one user? It’s going to be difficult without knowing the user id and without knowing the field names to look at. You can get the field groups if you have a user id and loop through the fields in that group, but without a user id there is nothing built into ACF to get the fields. You could construct an SQL query and get the values from the usermeta table (https://codex.wordpress.org/Class_Reference/wpdb) but you’ll need to have the field names.

  • I actually ended up going in a different direction. Since I only needed one post to be the Related post, I changed the field type from Relationship to Post Object. From here, when the page loads with the aforementioned query tags, I use javascript to set the value of #acf-field_<number>-input field to the post_id of the parent. Then, when saving, it properly sets the parent post.

    This is a bit hackish, but does what I need it to.

  • i have a working flexslider with acf-gallery.

    I dont know if it make a big difference,(because your code looks not that different than mine.) but i hope it works when you do it this way (like i do)

    register scripts inside functions.php

    <?php
    add_action('wp_enqueue_scripts', 'register_content_scripts');   
    function register_content_scripts(){
    wp_register_style( 'flexslider-custom-css', get_stylesheet_directory_uri() . '/css/flexslider/flexslider.css' );
    wp_register_script( 'acf-flexslider-scripts',  get_stylesheet_directory_uri() . '/js/jquery.flexslider-min.js',  array( 'jquery' ), 1, 1 );
    wp_register_script( 'flexslider-init',  get_stylesheet_directory_uri() . '/js/flex-init.js',  array( 'jquery' ), 1, 1 );
    }
    ?>

    inside gallery-template enqueue them

    <?php
    $images = get_field('slider');
    if( $images ):
    wp_enqueue_style( 'flexslider-custom-css' );
    wp_enqueue_script( 'acf-flexslider-scripts' );
    wp_enqueue_script( 'flexslider-init' );
    ?>
    <div id="slider" class="flexslider">
            <ul class="slides">
                <?php foreach( $images as $image ): ?>
                    <li>
                        <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
                        <p><?php echo $image['caption']; ?></p>
                    </li>
                <?php endforeach; ?>
            </ul>
        </div>
    <?php endif; 
    ?>
    

    use this inside flex-init.js

    jQuery(document).ready(function($) {
    $(".flexslider").flexslider({
    animation: "fade"
    });
    });

    try it and say if it works

  • use code like this that count images inside the gallery and depends on that count use a if else loop for the different outputs.

    <?php 
    $images = get_field('gallery'); 
    $total_images = count($images); //how many images are inside the gallery
    foreach( $images as $image ): 
    if ($total_images == 1){ //do what you wish i there is only one image
    echo '<img class="h400px" src="'. $image['sizes']['large'].'" alt="'.$image['alt'].'"  title="'.$image['title'].'"  />';
    } else { //do what you wish i there are multiple images
    echo '<img class="h200px" src="'. $image['sizes']['medium'].'" alt="'.$image['alt'].'"  title="'.$image['title'].'"  />';
    }
    endforeach;
    ?>

    depends on your needs choose at least one:

    • use the class and css to style the 2 imagesizes
    • add height param to the image
    • use own/additional media size with the sizes that you wish

    hope that help

  • Terribly Sorry… don’t know why it didn’t work…

    <?php
    $member_group_terms = get_terms( ‘systemcontents_category2′);
    $selected = get_sub_field(‘system_contents_posts’);
    ?>
    <?php
    foreach ( $member_group_terms as $member_group_term ) {
    $member_group_query = new WP_Query( array(
    ‘post_type’ => ‘pj_systemcontents2′,
    ‘systemcontents_category2′ => $selected,
    ‘tax_query’ => array(
    array(
    ‘taxonomy’ => ‘systemcontents_category2′,
    ‘field’ => ‘slug’,
    ‘terms’ => array( $member_group_term->slug ),
    ‘operator’ => ‘IN’
    )
    )
    )
    );?>
    <?php if ( $member_group_query->have_posts() ) : ?>
    <h3><?php echo $member_group_term->name; ?></h3>
    
    <?php while ( $member_group_query->have_posts() ) : $member_group_query->the_post(); ?>
    <?php echo get_post_meta($post->ID,’document-section’,true) ?>
    <?php echo get_post_meta($post->ID,’document-reference’,true) ?> <?php echo get_post_meta($post->ID,’document-sub-section’,true) ?>
    <?php endwhile; ?>
    
    <?php endif; ?>
    <?php
    // Reset things, for good measure
    $member_group_query = null;
    wp_reset_postdata();
    }
    ?>
  • Thanks again, Jonathan. Stellar support here. Wish I could bring you home and get you to help with all of my WP related questions!

    See you again on here someday, I’m sure. 🙂

  • I figured it out. I was trying to draw the front-end field name. I needed to go into SQL and get the correct row used there.

    add_filter('acf/load_value/name=employee_schedule', 'my_acf_load_value', 10, 3); //repeater_name
    function my_acf_load_value( $rows)
    {
     foreach( $rows as $key => $row ) {
      $column_id[ $key ] = $row['field_5625599634aa1'];
     }
     
     array_multisort( $column_id, SORT_ASC, $rows );
     return $rows;
    }
  • just to complete the thread. thats easy:

    add_action('admin_head', 'admin_styles');
    function admin_styles() {
        if( get_post_type() == "product" ) {
    	?>
    	<style>
    		.acf-editor-wrap iframe {
    			height: 100px !important;
    			min-height: 100px;
    		}
    	</style>
    	<?php
    	}
    }
  • Hum, I spoke too quickly. I can update the licence key but I can’t update the plugin :-/. I’ll do it manually.

  • i think i found it:

    $group_NAME = 'Attribute';
    $group_query = new WP_Query( array( 'post_type' => 'acf-field-group', 's' => $group_NAME) );
    $group_ID = $group_query->post->ID;
    $field_query = new WP_Query( array( 'post_type' => 'acf-field', 'post_parent' => $group_ID) );

    the second query returns me all available custom fields of the fieldgroup “Attribute”

  • okay. found it!

    $group_NAME = 'Attribute';
    $group_query = new WP_Query( array( 'post_type' => 'acf-field-group', 's' => $group_NAME) );
    $group_ID = $group_query->post->ID;
    $field_query = new WP_Query( array( 'post_type' => 'acf-field', 'post_parent' => $group_ID) );
  • same here. i try to get all available fields of a fieldgroup assigned to a specific post type:

    $group_NAME = 'Attribute';
    $the_query = new WP_Query( array( 'post_type' => 'acf-field-group', 's' => $group_NAME) );
    $group_ID = $the_query->post->ID; // returns the valid ID !
    $fields = array();
    $fields = apply_filters('acf/field_group/get_fields', $fields, $group_ID);

    but the $fields array is empty!

  • Hi @viorelepuran

    The scheduling of a post works the same as any wp cron so it would not make any difference if no one visits your site. I think the right way to go is to create your own cron job as you initially thought.

    To make wp cron more reliable is actually pretty simple if you have access to cron on your server/hosting.
    https://tommcfarlin.com/wordpress-cron-jobs/

    I don’t know what “Advanced Custom Fields Contact Forms” is but I assume it’s a third party plugin. I will assume it creates a CPT which all the submissions are saved to as posts.

    I would create a cron job that triggers a function. In the function you query the submissions for date values where the date is in two days from today. Then in the loop you find the users email and send out an email using wp_mail. It’s all fairly simple if you’re familiar with PHP 🙂

    Here’s how to get a date two days from now:
    $date = date('Ymd', strtotime('+2 days'));

    and a query

    
    $upcoming_query = new WP_Query(array(
    	'post_type' => 'submissions' //whatever it is
    	'meta_query' => array(
    		'key' => 'acffield',
    		'value' => $date,
    		'compare' => '='
    	),
    	'posts_per_page' => 100,
    	'no_found_rows' => true,
    	'update_post_term_cache' => false
    ));
    
  • Hi @alynefrancis

    Q1:
    An image is really a post type “attachment” as I’m sure you know. The ID in the $image is thus the attachments ID. So you should be able to fetch the term like:

    
    //will return an array of term objects.
    $terms = wp_get_object_terms($image['ID'], 'image_gallery');
    

    Q2:
    ACF uses the same image modals as WordPress core so this is really not an ACF thing. You’ve registered your custom taxonomy and now you need to add it to the modal. I don’t have any code for this but I’m sure you can find some by googling 🙂

    There’s also plugins out there and this is one of the most tested: https://wordpress.org/plugins/enhanced-media-library/

  • @joelstransky

    I think you’re pretty much there.
    You could set up each acf_form depending on a GET parameter (lets say step) so you’ll just check the step parameter and show a different form group for each step.

    If the form is supposed to submit a new post you’d probably have to find a way to send the new post id along from the first step to the subsequent ones.. I’m not sure you can do this by ACF.. there’s the %post_url% parameter for the redirect and perhaps there’s a %post_id% as well. Otherwise you could look into hooking in before ACF does it’s redirect and do it yourself and find the post ID to send along with it..

  • Yes. ACF would need to either keep track of what was deleted and submit some kind of delete flag or it would need to query the database before saving and compare the old data to the new data before saving. The final choice would be to delete all of the old content and then insert the new content.

    I don’t know how practical the first choice in and the last two would significantly slow down the admin because ACF would have to do twice as much work. I’m also not really sure how this would effect revisions.

    If really want that data to be removed then the best solution there is would be to create an acf/save_post filter that runs before ACF does the save. Then you could figure out how to compare the data and do the deleting.

    I’ve never really had a problem with some old data lingering in the db.

  • <?php 
    $images = get_field(‘bkg_slide_gallery’, 'option');
    if( $images ): ?>
    <ul class="clearfix row">
    <?php foreach( $images as $image ): ?>
    <li>
    <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
    <p><?php echo $image['caption']; ?></p>
    </li>
    <?php endforeach; ?>
    </ul>
    <?php endif; ?>
  • That would depend on how you’re matching them. You need to do a query or something to see if it already exists. How do you know which is which?

    Are you using a relationship field in the timesheet? Check to see if the relationship already exists. If yo give me more information about how you’re creating the new post I might be able to give you more information. But thinking about it now I’d say that adding a relationship field and updating it mighe be the easiest solution.

  • Hi John,

    Thanks. Much appreciated. It works perfectly.

    I just had one more question how do I prevent duplication of Payslips if the the same timesheet is updated.

    I want to make sure the data is updated. Currently every time I update the timesheet a new payslip with the same title is created.

    Cheers,
    Ed

  • John, you’re a genius (even if you didn’t realize it)! That code did the trick:
    http://njcai.pairserver.com/tag/asphaltmaintenanceseal-coating/

    What I ended up with is:

    <?php 
    // Get the logo, if it exists.
    if( get_field('sponsor_logo') ):
    $image = get_field('sponsor_logo');
    if (intval($image) == $image) {
      $image = wp_get_attachment_image_src(intval($image), 'full');
      $image = $image[0];
    }
    ?>
    <img class="sponsorlogo" src="<?php echo $image ; ?>" width="120" height="120" alt="<?php the_field('sponsor_company_name'); ?>">
    <?php endif; ?>

    Thanks so much for your help with this!

  • So, this is what I would do, and this is because it’s only something that I’d need to use once. I’d build a php script that connected directly to the WP database.

    Search the user table and get the list of users and needed user data

    Loop through each user and construct a string to use to look for the image

    search the post table column guid or post_name LIKE %$name_value% and get the ID of the attachement

    Each record for and ACF field requires two entries in the usermeta table

    INSERT INTO wp_usermeta (user_id, meta_key, meta_value) VALUES ("$user_id", "$acf_field_name", "$post_id"), ("$user_id", "_$acf_field_name", "$acf_field_key")

    I’d do some testing with one or two users to make sure it works and delete anything it added so you don’t get duplicates. Make sure you back up the database. Then I’d set it up to run as a cron job because this will likely timeout if you try to run it in a browser.

  • I went in and disabled everything except ACF and Custom Post Type UI (since I’m using this for the custom post type) and the problem is still there. However, it made me think of what I had to do to get the tag archives working in the first place. Apparently there is an issue with WordPress archives grabbing tags from custom posts types, so I had to use this code in my functions.php file:

    //Tag Archive
    function namespace_add_custom_types( $query ) {
      if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
        $query->set( 'post_type', array(
         'post', 'nav_menu_item', 'sponsors'
    		));
    	  return $query;
    	}
    }
    add_filter( 'pre_get_posts', 'namespace_add_custom_types' );

    And, for the heck of it, here are the other custom scripts I’m running in the functions.php file:

    /*
    * Allows extra HTML items in to the_excerpt instead of stripping them like WordPress does
    */
    function theme_t_wp_improved_trim_excerpt($text) {
    global $post;
    if ( '' == $text ) {
    $text = get_the_content('');
    $text = apply_filters('the_content', $text);
    $text = str_replace(']]>', ']]>', $text);
    $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
    $text = strip_tags($text, '<p>,<ul>,<li>,<ol>,<b>,<strong>,<br>,<a>,<br />');
    $excerpt_length = 70;
    $words = explode(' ', $text, $excerpt_length + 1);
    if (count($words)> $excerpt_length) {
    array_pop($words);
    array_push($words, '[...]');
    $text = implode(' ', $words);
    }
    }
    return $text;
    }
    
    remove_filter('get_the_excerpt', 'wp_trim_excerpt');
    add_filter('get_the_excerpt', 'theme_t_wp_improved_trim_excerpt');
    
    //Drop Down Menu for Tags
    function drop_tags()
    {
    echo "<select class=taglist onChange=\"document.location.href=this.options[this.selectedIndex].value;\">";
    echo "<option>Select a Category:</option>\n";
    foreach (get_tags() as $tag)
    {
    echo "<option value=\"";
    echo get_tag_link($tag->term_id);
    echo "\">".$tag->name."</option>\n";
    }
    echo "</select>";
    }
    
    // Custom Footer Menu Walker
    class example_nav_walker extends Walker_Nav_Menu {
    
        var $current_menu = null;
        var $break_point  = 6;
    
        function start_el(&$output, $item, $depth, $args) {
    
            global $wp_query;
    
            if( !isset( $this->current_menu ) )
                $this->current_menu = wp_get_nav_menu_object( $args->menu );
    
            if( !isset( $this->break_point ) )
                $this->break_point = ceil( $this->current_menu->count / 2 ) + 1;    
    
            $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
    
            $class_names = $value = '';
    
            $classes = empty( $item->classes ) ? array() : (array) $item->classes;
            $classes[] = 'menu-item-' . $item->ID;
    
            $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
            $class_names = ' class="' . esc_attr( $class_names ) . '"';
    
            $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
            $id = strlen( $id ) ? ' id="' . esc_attr( $id ) . '"' : '';
    
            if( $this->break_point == $item->menu_order )
                $output .= $indent . '</li></ul><ul id=menu-main-menu-2><li' . $id . $value . $class_names .'>';
            else
                $output .= $indent . '<li' . $id . $value . $class_names .'>';
    
            $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
            $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
            $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
            $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';
    
            $item_output = $args->before;
            $item_output .= '<a'. $attributes .'>';
            $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
            $item_output .= '</a>';
            $item_output .= $args->after;
    
            $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
        }
    }
    
    I'm not certain that this is the cause of the conflict, but I figured it would be relevant since it's helping create the archive pages.
  • There must be some reason that it’s returning an id instead of the URL. There’s been another question with the same problem recently… in the last few months.

    but I can’t find it. If the same field is returning a url in one place but an id in another then you’re got some kind of compatibility issue. You should deactivate other plugins and see what’s causing it because it will just keep giving you problems. The last time I’m pretty sure it had to do with a woocommerce add on, but it could be anything.

Viewing 25 results - 15,576 through 15,600 (of 21,380 total)