Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • Of course. I have five different option pages.
    Create a function for each option page with the the condition above and replace the string “acf-options-adverts” with the slug of the attached option page (you may have a look in the url-bar of each page).

    In your case for example I could imagine the code to look like this:

    if (strpos($screen->id, "acf-options-product") == true) {…
    if (strpos($screen->id, "acf-options-service") == true) {…
    if (strpos($screen->id, "acf-options-theme-option") == true) {…
  • The part that works for me from the release notes is:

    Core: Fixed bug when adding ‘post_parent’ value to post_object/relationship query args

    It’s not a front-end admin feature. You need to use a filter in your functions to alter the query:
    http://www.advancedcustomfields.com/resources/acf-fields-relationship-query/

  • It says line 20:

    <?php} if ( $quick_link_column == "yes" ) { // Continue with the other links ?>

  • is it possible to edit other settings too?
    i had a hook that works for the default wysiwyg.
    but not for the acf_wysiwyg-fields. (it looks like my hook is not fully executed)

    add_action( 'wp_tiny_mce_init', function () {
        ?>
        <script>
         function editShortcut_tiny_mce_init(ed) {
            ed.on('init', function () {
             // Note these lists may not be complete & that other tinymce plugins can add their own shortcuts anyway.
                    var ctrls = [ 'u', '1', '2', '3', '4', '5', '6', '7', '8', '9', 's', 'k', 'Alt+F', 'P' ];
                    var modKeys = [ 'c', 'r', 'l', 'j', 'q', 'u', 'o', 'n', 's', 'm', 'z', 't', 'd', 'h', 'o', 'x', 'a', 'w' ];
                    // Overwrite shortcuts with no-op function. Key sequences will still be captured.
                    for (var i = 0; i < ctrls.length; i++ ) {
                        this.addShortcut('ctrl+' + ctrls[i], '', function () {});
                    }
                    for (var i = 0; i < modKeys.length; i++ ) {
                        this.addShortcut('alt+shift+' + modKeys[i], '', function () {});
                    }
        });
        }
        </script>
        <?php
        
    });
    
    function my_acf_editor( $mceInit, $editor_id ) {
    	$mceInit['setup'] = 'editShortcut_tiny_mce_init';
    	// What goes into the 'formatselect' list
    	$mceInit['block_formats'] = 'Header 3=h3;Header 4=h4;Header 5=h5;Paragraph=p;Code=code';
    	$mceInit['paste_word_valid_elements'] = '-strong/b,-em/i,-p,-ol,-ul,-li,-h3,-h4,-h5,-h6,-p,-table[width],-tr,-td[colspan|rowspan|width],-th,-thead,-tfoot,-tbody,-a[href|name],br,del';
    		
    	$mceInit['paste_strip_class_attributes'] = 'all';
    	$mceInit['toolbar1'] = 'bold,italic,formatselect,bullist,numlist,blockquote,link,unlink,undo,redo';
    
    	return $mceInit;
    }
    add_filter('tiny_mce_before_init', 'my_acf_editor')
    

    i need a solution that works inside function.php or better, inside my custom plugin.
    can anyone help me? please.

    my aim is: to have a verry simple wysiwyg that only allow things defined by me.
    only edit toolbar is not enough, because the user can avoid these restrictions with shortkeys and/or copy&paste from word.

  • Hi RBmac,

    Been away from the desk. Thanks for responding. Of course, not in the loop – makes total sense and now have it working. Setup_postdata was the answer.

    Code for anyone looking for it:

    <?php
    $args = array(
    	'post_type' => 'post',
    	'posts_per_page' => 1,
    	'meta_query' => array(
    		array(
    			'key' => 'field', // name of custom field
    			'value' => '"' . get_the_ID() . '"',
    			'compare' => 'LIKE'
    		)
    	)
    );
    $lastposts = get_posts( $args );
    foreach ( $lastposts as $post ) :
      setup_postdata( $post ); ?>
    	<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    	<p><?php the_content(); ?>
    <?php endforeach; 
    wp_reset_postdata(); ?>
  • Well, this was not so much a problem with ACF as working around the need of WP to automatically unserialze and double/triple/quadruple serialize values.

    I needed to add a filter to the acf/load_value hook for the field in question, get the value of the field directly using get_post_meta() and then make sure it was formatted correctly before returning it to ACF.

  • I found workaround:

    add_action( 'admin_footer', function() {
    	?>
    	<script type="text/javascript">
    		var tmp_acf_serialize_form = acf.serialize_form;
    		acf.serialize_form = function( $el, prefix ) {
    			var data = tmp_acf_serialize_form( $el, prefix );
    			data['post_id'] = <?php echo get_the_id(); ?>;
    			return data;
    		}
    	</script>
    	<?php
    } );

    and now in add_filter( 'acf/validate_value/... you can use $_REQUEST['post_id'];

    There’s needs to be checked if acf exists in js…

  • I think i got it now:) So the links with Quicklinks “Yes” checked appear only in the sidebar, if that’s the case I think it will be a lot simpler if you make a separate group of fields for the sidebar as Quicklinks without the need to have the True/False Yes/No condition.

    But if you have to stick with the same setup i think there is a way to conditionally show the <h1>. Please check the commented code below and test if it works:

    <div class="quick-link-sidebar">
    
    	<?php if( have_rows('pro_resource_url') || have_rows('pro_resource_download') ): ?>
     	
    			<?php  	
    				$h1 = true; // add a simple boolean set to true
    				// loop through the rows of data
    			    while ( have_rows('pro_resource_url') ) : the_row(); ?>
    
    			    <?php $quick_link_column = get_sub_field('quick_link');  ?>
    					
    					<?php if ( $h1 && $quick_link_column == "yes" ) { // The first quicklink found 'yes' will display the <h1> and will open the <ul>?>
    
    					<h1>Quicklinks</h1>			
    					<ul class="resource-links"> 
    					<li class="<?php echo the_sub_field('indy_content'); ?>">
    							<a href="<?php the_sub_field('pro_url'); ;?>"><?php the_sub_field('pro_resource_url_name'); ?></a>
    					</li>
    					<?php $h1 = false; //now set the $h1 to false so only it doesn't display multiple times ?>
    					<?php} if ( $quick_link_column == "yes" ) { // Continue with the other links ?>						
    			     	<li class="<?php echo the_sub_field('indy_content'); ?>">
    			     			<a href="<?php the_sub_field('pro_url'); ;?>"><?php the_sub_field('pro_resource_url_name'); ?></a>
    			     	</li>
    
    			        <?php } else {
    					// something else
    			        } ?>
    			     
    			<?php endwhile; ?>
    			<?php wp_reset_postdata(); ?>
    
    			<?php  	// loop through the rows of data
    			    while ( have_rows('pro_resource_download') ) : the_row();
    
    			    $quick_link_column = get_sub_field('quick_link');  ?>
    					
    					<?php if ( $h1 && $quick_link_column == "yes" ) {// Same if a download link is found here?>
    					<h1>Quicklinks</h1>			
    					<ul class="resource-links">								
    			     	<li class="<?php echo the_sub_field('indy_content'); ?>">
    			     		<a href="<?php the_sub_field('pro_download_link'); ;?>"><?php the_sub_field('pro_download_name'); ?></a>
    			        </li>
    					<?php $h1 = false; ?>
    					<?php} if ( $quick_link_column == "yes" ) { // Continue with the other links ?>	
    					<li class="<?php echo the_sub_field('indy_content'); ?>">
    							<a href="<?php the_sub_field('pro_download_link'); ;?>"><?php the_sub_field('pro_download_name'); ?></a>
    					</li>
    			        <?php } else {
    					// something else
    			        } ?>
    			     
    			<?php endwhile; ?>
    			<?php wp_reset_postdata(); ?>
    			<?php if ($h1) {//do nothing
    			}else{ ?>
    			</ul>
    			<?php endif; ?>
    			
    		
    		
    
    </div> 
    
  • Thanks for the reply but that answer does not help me. That makes the heading appear in the Sidebar whenever an entry exists whether it is located in the main content area or sidebar. So if the entry is meant for the main content, a heading is injected into the sidebar with no content beneath it which is undesirable.

    I had gotten that far, but I need it to display the heading in the sidebar ONLY if the “yes” check box (indicating the entry should be a Quicklink and therefore located in the sidebar) is chosen.

    Any other thoughts? Thanks again for your help with this, it really gotten me stuck.

  • Figured it out myself:

    
    jQuery(document).ready(function()
    {
    	jQuery(window).off("beforeunload", null);
    });
    
  • Hello,

    Set the output of the image field to: “Image Array” in the ACF field set.

    Then you can view your images with custom size like this:

    
    <?php $image = get_field("image") ?>
    <img src="<?= $image["sizes"]["post-portrait-featured-image"] ?>" alt="<?= $image["alt"] ?>" />
    
  • Hi kkyang,

    You can do so by editing the capability of the options page.

    Set it to a capability only a super admin has

    For example:

    
    $options = acf_add_options_page(array(
    		"page_title"    => "Options",
    		"menu_title"    => "Options",
    		"menu_slug"     => "options-theme",
    		"capability"    => "manage_sites",
    		"redirect"      => false
    		));
    

    For more capabilities see:

    http://codex.wordpress.org/Roles_and_Capabilities#Capability_vs._Role_Table

  • Just after the Radio Button Field create whatever field you want to use to add hours etc. and on that field selected Conditional Logic ‘Yes’ and ‘Show this field if’
    and from the drop down menus:
    1 Select ‘Radio Button Field Name’
    2 Select ‘is equal to’
    3 Select ‘+add hours’

    Check the edit post page to see that when you select +add hours the field you created will show next. Hope this helps!

  • Do you mean how to get the ID or the title of the artist of the current post from the relationship field instead of using a hard coded name like in your example ‘natasha_yudina’ or you want to show only post from ‘natasha_yudina’?

    Either way you are using compare the wrong way I guess. This is purely a wordpress question.

    Change this:

    array(
            'key' => 'artist', // name of custom field
    	'value' => 'name', // matches exaclty "123", not just 123.This prevents a match for "1234" 
    			'compare' => 'natasha_yudina'
    		)

    To this:

    array(
           'key' => 'artist', // name of custom field
            'value' => 'natasha_yudina' // value of custom field
            )
  • This is a basic wordpress loop condition and not an ACF issue.
    Simply put your heading after the if condition.

    <?php if( have_rows('pro_resource_url') || have_rows('pro_resource_download') ): ?>
           <h1>Quicklink</h1>
           <ul class="resource-links">
  • @RenaissanceDesign did you get this working?

    Do you have a possible example of the code you used to query the posts as you mentioned above?

  • Hey @magnakai On my version of ACF5 you can add a “Page Type is equal to Front Page” rule. Is this not available for you?

  • Hi everyone,

    I believe I have a more or less decent looking workaround for this issue, based on the same idea JoepR had. It allows you to mark any number of options pages as “global”, i.e. they are not translatable and will always display the options in the default language. All other options pages would remain translatable.

    
    /**
     * Create the options page that we will later set "global"
     */
    acf_add_options_page(array(
          'page_title'  => 'Test',
          'menu_title'  => 'Test',
          'menu_slug'   => 'test',
    ));
    
    /**
     * Force ACF to use only the default language on some options pages
     */
    function cl_set_global_options_pages($current_screen) {
    
      // IDs of admin options pages that should be "global"
      $page_ids = array(
        "toplevel_page_acf-options-test"
      );
    
      if (in_array($current_screen->id, $page_ids)) {
        add_filter('acf/settings/current_language', 'cl_acf_set_language', 100);
      }
    }
    add_action( 'current_screen', 'cl_set_global_options_pages' );
    
    function cl_acf_set_language() {
      return acf_get_setting('default_language');
    }
    
    /**
     * Wrapper around get_field() to get the "global" option values.
     * This is the function you'll want to use in your templates instead of get_field() for "global" options.
     */
    function get_global_option($name) {
      add_filter('acf/settings/current_language', 'cl_acf_set_language', 100);
      $option = get_field($name, 'option');
      remove_filter('acf/settings/current_language', 'cl_acf_set_language', 100);
      return $option;
    }
    

    I’d appreciate any feedback on the concept. Couldn’t figure out any scenarios where it would break, but maybe I missed something.

  • Ok, I actually solved my own question.
    The issue is when you select the following:
    Show this field group if
    Logged In User Type = Administrator.
    http://cl.ly/image/0t0q0e3M090S

    Weird!

  • Working version of the code from @roflman79.

    /**
     * Exclude current post/page from relationship field results
     */
    
    // 1. Add the name=[NAME_OF_RELATIONSHIP_FIELD].
    add_filter('acf/fields/relationship/query/name=[NAME_OF_REALTIONSHIP_FIELD]', 'exclude_id', 10, 3);
    
    // 2. Add the $field and $post arguments.
    function exclude_id ( $args, $field, $post ) {
    
        //3. $post argument passed in from the query hook is the $post->ID.
        $args['post__not_in'] = array( $post );
        
        return $args;
    }
  • Looks like this issue is back…

    – WP 4.1 with ACF PRO 5.1.5
    – Totally clean install to test this issue
    – ACF is the only plugin
    – Theme is bare except for WP_DEBUG enabled in functions.php
    – No PHP errors on admin page or JS errors in console

    The field group holds a repeater field with a WYSIWYG field inside. When editing a post, re-sorting the repeater causes the WYSIWYG field to remove all paragraph and line breaks. This only happens when the WYSIWYG is in Visual mode (Text mode preserves the breaks OK).

    I made a quick 1 min. screencast showing the issue here: https://www.youtube.com/watch?v=JoC71DGS1eM

    Any ideas? Thank you!

  • Ahh, I see what you’re trying to do. I’ve never done it, and can’t answer your question. But I did find something that might steer you in the right direction.

    This looks like a good start:
    http://www.advancedcustomfields.com/resources/using-acf_form-to-create-a-new-post/

    Then this answers the first question I had looking at the example:
    http://support.advancedcustomfields.com/forums/topic/front-end-creat-post-2/

    As far as the repeater goes, it’s pretty awesome and it took me a bit to wrap my head around at first. It’s basically a group of fields that a user can keep adding new instances of.

    I hope this helps and good luck.

  • It’s a custom post type called Events. Right now, it’s just a textbox called Test Field. For now, I need to be able to put textbox and textarea on the front end (but would like to maybe put a repeater there, if possible, but I’m not sure that it is).

    This is above the header:

    <?php
     
    if ( isset( $_POST['submitted'] ) && isset( $_POST['post_nonce_field'] ) && wp_verify_nonce( $_POST['post_nonce_field'], 'post_nonce' ) ) {
     
        if ( trim( $_POST['postTitle'] ) === '' ) {
            $postTitleError = 'Please enter a title.';
            $hasError = true;
        }
     
        $post_information = array(
            'post_title' => wp_strip_all_tags( $_POST['postTitle'] ),
            'post_content' => $_POST['postContent'],
            'post_type' => 'events',
            'post_status' => 'publish'
        );
     
        wp_insert_post( $post_information );
     
    }
     
    ?>

    And this is the actual form:

    <form action="" id="primaryPostForm" method="POST">
     
        <fieldset>
            <label for="postTitle"><?php _e('Post Title:', 'framework') ?></label>
     
            <input type="text" name="postTitle" id="postTitle" class="required" value="<?php if ( isset( $_POST['postTitle'] ) ) echo $_POST['postTitle']; ?>" />
        </fieldset>
     
        <fieldset>
            <label for="postContent"><?php _e('Post Content:', 'framework') ?></label>
     
            <textarea name="postContent" id="postContent" rows="8" cols="30" class="required"><?php if ( isset( $_POST['postContent'] ) ) { if ( function_exists( 'stripslashes' ) ) { echo stripslashes( $_POST['postContent'] ); } else { echo $_POST['postContent']; } } ?></textarea>
        </fieldset>
     
        <fieldset>
            <input type="hidden" name="submitted" id="submitted" value="true" />
     
            <button type="submit"><?php _e('Add Post', 'framework') ?></button>
            <?php wp_nonce_field( 'post_nonce', 'post_nonce_field' ); ?>
        </fieldset>
     
    </form>
    <?php if ( $postTitleError != '' ) { ?>
        <span class="error"><?php echo $postTitleError; ?></span>
        <div class="clearfix"></div>
    <?php } ?>

    When I post to the Events post type from the front end, I just need to be able to put data in these custom fields, also.

  • You could check to see if the date has changed from the last event displayed, and if it has, then you display the date; otherwise you just display the event.. something along the lines of:

    
    // initialize the last displayed date.. since this is before the loop, we'll just make it an empty string
    $lastDate = '';
    
    while ($schedule_query->have_posts()) : $schedule_query->the_post(); ?>
    <?php // now that we're in the loop, start outputting events ?>
    <div class="screening">
    						<h2><strong><?php $date = DateTime::createFromFormat('Ymd', get_field('screening_date'));
    
    // now that we have the event's date, see if it matches the last date displayed.. if not, we'll update $lastDate with the event's date and display it
    
    if ($date != $lastDate) {
    $lastDate = $date;
    echo $date->format('F d, Y'); ?>, </strong></h2>
    }
    
    ...
    endwhile;
    ?>
  • +1 to this feature request! Thanks 🙂

Viewing 25 results - 17,401 through 17,425 (of 21,345 total)