Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • Hi @Cornholio

    A few things. I don’t believe you need to use LIKE as per the meta compare.

    The true / false field saves either ‘0’ or ‘1’ for the value, so this compare should simply be ‘=’

    As for the numberposts, try changing this to posts_per_page

    Good luck
    E

  • Hi @Bassscape

    Great work o the query!

    Cheers
    E

  • Hi @roflman79

    Sure, you can use the following filter to modify the query args!

    http://www.advancedcustomfields.com/resources/filters/acf-fields-relationship-query/

    Thanks
    E

  • Hi @dreamzsiva

    You have 2 options:

    1. Leave the HTML as is, inspect it in firebug and then use CSS to alter teh design using floats / widths

    2. Use jQuery to pull out the field divs and then place them into placeholders of your own markup

    Good luck!

    Cheers
    E

  • Hi @cyberwani

    If you are using the relationship field, you will be happy to know there is a WP filter available to modify the query args.

    You could use the current $post_ID parameter to modify the question to only load posts which have a parent of $post_ID

    The filter is documented here:
    http://www.advancedcustomfields.com/resources/filters/acf-fields-relationship-query/

  • Hi @JAVOB

    I suspect the issue is due to the way that ACF instantiates the WP tinymce. Due to the requirements of the repeater and flexible content field, the WYSIWYG field must be duplicate-able at run time, which the default WP WYSIWYG does not offer.

    I have a feeling that if install and use the WP WYSIWYG field (add-on) your shortcode button will work as expected. If not, the issue most likely lies within the shortcode plugin as it expects only 1 wysiwyg on the page.

    Try out the add-on but be aware it won’t work within a repeater / flexible content field.

    Thanks
    E

  • Quick update: While the class acf-conditional_logic-hide that the tabs need to be hidden still disappears on save, toggling any other field in the ACF block triggers the script and the acf-conditional_logic-hide class is reapplied. See screenshots below.

    As a workaround for the fact that while the tabs themselves don’t respect my desire to hide them, I’ve set all options inside those tabs to hidden and added an additional ACF that simply says “These options are not available” that is not hidden. This way even if the tabs show up users get an explanatory message and can’t tweak anything.

    Several of these tabs should be hidden, but aren't.

    The tabs go back to their hidden state after toggling any other field in the ACF block.

  • You can use this code in your functions.php file

    // Restrict media library to show only own user files
    add_action('pre_get_posts','ml_restrict_media_library');
    function ml_restrict_media_library( $wp_query_obj ) {
    
    	global $current_user, $pagenow;
    
    	if( !is_a( $current_user, 'WP_User') )
    
    		return;
    
    	if( 'admin-ajax.php' != $pagenow || $_REQUEST['action'] != 'query-attachments' )
    
    		return;
    
    	if( !current_user_can('delete_pages') )
    
    		$wp_query_obj->set('author', $current_user->ID );
    
    	return;
    
    }
    
  • Here’s your code with my code combined 🙂

    <?php  			
    	if(get_field('image_slider_illustrations'))
    	{
    		echo '<ul class="slider">';
    		while(has_sub_field('image_slider_illustrations'))
    		{	
    
    			$attachment_id = get_sub_field('illustrations_image');
    			$size = "full"; // (thumbnail, medium, large, full or custom size)
    			
    			$image = wp_get_attachment_image_src( $attachment_id, $size );
    
    			$attachmentinfo = get_post( $attachment_id );
    			$alt = get_post_meta($attachmentinfo->ID, '_wp_attachment_image_alt', true);
    
    			echo '<li><img src="' . $image[0] . '"  alt="' . $alt  . '"/></li> ';               
    		}	 
    		echo '</ul>';
    	}	 
    ?>

    Just tried that and got the expected result – let me know if you’ve still got no joy

  • Hi,

    Thanks for your reply, i managed to make it work however i have an issue with a few fields.

    The create new post form, successfully creates the listing and i’m also grabbing the post title and the post content and the featured image through custom fields. This works.

    I have then attempted to modify the action so instead of inserting a new post, he would update it. The edit works but some of the fields are not updating. For example when i modify the post and i attempt to modify the custom field that has been used for the post title, it isn’t updating the post title but just the custom field.

    This is part of the code used.

    global $current_user;
    
        // check if this is to be a new post
        if( $post_id != 'new_listing' )
        {
            return $post_id;
        }
     
        // Create a new post
        $post = array(
            'post_status'  => get_field('default_listing_submission_status','option') ,
            'post_title'  => $_POST["fields"]['field_522f30035c85b'],
            'post_content' => $_POST["fields"]['field_5230848453094'],
            'post_type'  => 'listing' ,
        );
    
        $post_edit = array(
            'post_status'  => get_field('default_listing_submission_status','option') ,
            'post_title'  => 'test',
            'post_content' => 'test2',
            'post_type'  => 'listing' ,
        ); 
    
     //add listing
        if( $post_id = 'new_listing' ) {
        	$post_id = wp_insert_post( $post );
        } else {
        	$post_id = wp_update_post( $post_edit );
        }
    

    Do you have any idea why the form wouldn’t update the post title or the content ?

    Thank you. If needed i can post the whole code but i don’t anything else in the action is interfering with it.

  • It doesn’t seem to be working. Its using a repeater to add new images for a image slider i have. Is that why its not working? And yes its set up to display image ID now.

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
      <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
      
      
    
    <?php 
    				
    	$attachment_id = get_sub_field('illustrations_image');
    	$size = "full"; // (thumbnail, medium, large, full or custom size)
     				
     	$image = wp_get_attachment_image_src( $attachment_id, $size );
    
     	$attachmentinfo = get_post( $attachment_id );
    
    	$alt = get_post_meta($attachmentinfo->ID, '_wp_attachment_image_alt', true);
    
    ?>
    
    <ul class="slider">
    <li><img src="<?php echo $image[0]; ?>" alt="<?php echo $alt; ?>" /><li>
    </ul>
    
    </div>
  • Thanks for your input Elliot, it led me on to find my solution.

    I realised I wasn’t using the LIKE operator for my meta_value query and therefore the wildcard values weren’t be recognised. I changed my query to the following and it now returns posts:

    $games_id_array = $wpdb->get_results(
    	$wpdb->prepare( 
    		"
    			SELECT * 
    			FROM wppp_postmeta
    			WHERE meta_key LIKE %s
    			AND meta_value LIKE %s
    		",
    		'contributing_game_creators_%_game_creator_roles',
    		'%'.$search_value.'%'
    	)
    );
  • You’ll need to have the image set as Image ID

    then use something like:

    <?php 
    				
    	$attachment_id = get_sub_field('illustrations_image');
    	$size = "full"; // (thumbnail, medium, large, full or custom size)
     				
     	$image = wp_get_attachment_image_src( $attachment_id, $size );
    
     	$attachmentinfo = get_post( $attachment_id );
    
    	$alt = get_post_meta($attachmentinfo->ID, '_wp_attachment_image_alt', true);
    
    ?>
    <img src="<?php echo $image[0]; ?>" alt="<?php echo $alt; ?>" />

    You’ll need to edit it to go in amongst your loop but hopefully you’ll get the jist.

  • The “§ruleS” was just a spelling mistake in the topic, I did use the original array name in the code.
    I did write an own code, but I now used the snippet from the documentation. The exact code is:

    add_filter('acf/location/rule_types', 'acf_location_rules_types');
    function acf_location_rules_types( $choices )
    {
        $choices['Basic']['user'] = 'User';
     
        return $choices;
    }
    
    add_filter('acf/location/rule_operators', 'acf_location_rules_operators');
    function acf_location_rules_operators( $choices )
    {
        $choices['<'] = 'is less than';
        $choices['>'] = 'is greater than';
     
        return $choices;
    }
    
    add_filter('acf/location/rule_values/user', 'acf_location_rules_values_user');
    function acf_location_rules_values_user( $choices )
    {
        $users = get_users();
     
        if( $users )
        {
            foreach( $users as $user )
            {
                $choices[ $user->data->ID ] = $user->data->display_name;
            }
        }
     
        return $choices;
    }
    
    add_filter('acf/location/rule_match/user', 'acf_location_rules_match_user', 10, 3);
    function acf_location_rules_match_user( $match, $rule, $options )
    {
        $current_user = wp_get_current_user();
        $selected_user = (int) $rule['value'];
     
        if($rule['operator'] == "==")
        {
        	$match = ( $current_user->ID == $selected_user );
        }
        elseif($rule['operator'] == "!=")
        {
        	$match = ( $current_user->ID != $selected_user );
        }
     
        return $match;
    }
    

    The code is placed at the very bottom of my theme’s functions.php to ensure that it isn’t executed too early.

  • In your frontend, you’ll have to count number of elements in the repeater field array. So something like this:

    <?php
    
    // pre define the allowed columns
    $allowed_classnames = array(
        1 => 'full',
        2 => 'half',
        3 => 'third',
        4 => 'fourth',
        5 => 'fifth',
    );
    // get the count on the repeater field
    // mabye use get_sub_field() instead of get_field() if it's nested
    $number_of_cols = count( get_field( '<repeater>' ) );
    
    // set a default classname
    $classname_to_use = $allowed_classnames[1];
    
    // check if the $number_of_cols exist in the predefined classnames
    if ( array_key_exists( $number_of_cols , $allowed_classnames ) ) {
        // set the classname to be used
        $classname_to_use = $allowed_classnames[$number_of_cols];
    }
    
    while( has_sub_field( '<repeater>' ) ) : ?>
        <div class="<?php echo esc_attr( $classname_to_use ); ?>">
            <?php the_sub_field( '<repeater_content>' ); ?>
        </div>
    <?php endwhile; ?>
    

    Please not that I just briefly tested it on a site I’m working on. You’ll have to replace the '<repeater_content>' and '<repeater>' with your actual field names.

  • Hi @aaronrobb
    Can you post the code you use to output VISA?

    Also, can you check the DB wp_postmeta table and find the row for this value and the post_id in question? Is the value stored correctly?

    Thanks
    E

  • Hi @Bassscape

    Your above query will only find posts (that is if the query works as expected) that have Concept and Design selected as the value.

    To allow for a value within the array, you shoudl take a look at the checkbox docs:
    http://www.advancedcustomfields.com/resources/field-types/checkbox/

    On that page, you will see how to use a LIKE statment in the meta_query to match a value.

    I have not yet combined this with a sub field DB search, but it must be possible with SQL.

    Good luck mate

    Cheers
    E

  • Hi @youngwolf0

    Your code looks perfect, so for that great work.

    Your next step is to debug the function to find out at what line it is failing.

    Firstly, turn on DEBUG MODE in your wp-config.php file and then use a simple script like so to test that your loop is working:

    
    <?php 
    
    $user = "user_" . $member->ID;
    
    echo '<pre>';
    	print_r( $user );
    echo '</pre>';
    
    ?>
    
  • Hi @figureone

    I had previously used that code (that is why it is commented out).
    I had to remove it due to multiple issues on many servers.

    Although the code makes logical sense, it did not work across all servers and many WYSIWYG started double escaping or even removing completely special characters.

    I’m not confident enough to put this back in, and I do apologies that this doesn’t leave you with much option, but perhaps you could chat to your server and change your magic quotes setting?

    Thanks
    E

  • Hi @hummelmose

    Thanks for the clarification. This is how I would do it.

    Add an action to the wp action. This action is run when WP is ready to function.
    Look at the URL (find the url in the $_SERVER array) and check if the url follows your above pattern. You can check for a patern with regexp.

    After the matching is done and you have a variable holding the $article_id, your next step is to find the post that has a matching custom field value.

    You can query the WP posts with teh get_posts function as shown here:
    http://www.advancedcustomfields.com/resources/how-to/how-to-query-posts-filtered-by-custom-field-values/

    Then, once you have the $post object, you can redirect to it like so:

    
    wp_redirect( get_permalink( $post->ID ) );
    exit;
    

    I hope the above makes sense. You may need to get some help from a PHP / WP dev if you can’t get it to work.

    Good luck mate.

    Cheers
    E

  • I actually ended up coding a basic importer that was quite specific to our csv. It does allow for mapping CSV headers against ACF fields, but it isn’t particularly elegant or completely reliable right now. I learned quite a bit whilst doing it and will hopefully be going back to produce something more robust, I think ACF could do with it!

  • Sorry about that; I think even I was confused on what I wanted to do…

    The code below gave me what I wanted; I’m always open to tips on optimizing it further.

    <?php if(get_field('choose_layout') == "1col")
    { ?>
       	<p><?php the_field('single_column'); ?></p>
    <?php } elseif (get_field('choose_layout') == "2col")
    { ?>
    	<p><?php the_field('two_columns_left'); ?></p>
    	<p><?php the_field('two_columns_right'); ?></p>
    <?php } elseif (get_field('choose_layout') == "3col")
    { ?>
    	<p><?php the_field('three_columns_left'); ?></p>
    	<p><?php the_field('three_columns_middle'); ?></p>
    	<p><?php the_field('three_columns_right'); ?></p>
    <?php } ?>
  • hi Elliot.

    we are trying to change it but still it wont work
    can you tell me how to change it?

    the php code is.

    <?php
    /*
    * Template Name: Onze scholen
    */
    ?>
    <?php get_header(); ?> 
    <div class="slider-divider"></div>
    <div class="wrapper">
    	<div class="content">
    		<div class="main-content">
    			<h1><?php the_title(); ?></h1>
    			
    				<ul>
    <?php if(get_field('scholen')): ?>
     
    	<ul>
     
    	<?php while(has_sub_field('scholen')): ?>
    		<li><img src="<?php the_sub_field('school-afbeelding'); ?>" width="200"; alt="" />
    					<?php the_sub_field('school-naam'); ?></li>
     
    	<?php endwhile; ?>
     
    	</ul>
     
    <?php endif; ?>
    	
    			</div>
    		</div>
    	</div>
    </div>
    <?php get_footer(); ?>
  • I wrote the following function and call and placed them in the active themes functions.php file:

    set_legacy_members(1);
    function set_legacy_members($members_value) {
        $members = get_users();
        $is_member = 'field_522f3c55f16be';
    		
        foreach ($members as $member) {
        	$user = "user_" . $member->ID;
            update_field($is_member, $members_value, $user);
        }
    }

    However this hasn’t worked, the field is still set to false for every member, what am I doing wrong?

  • This reply has been marked as private.
Viewing 25 results - 20,526 through 20,550 (of 21,337 total)