Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • There are multiple recent sources saying it does improve security, including a VERY big company behind Plesk and highly rated plugin developers like WMUDEV.

    I read you article and while it seems correct there is a litte point they’ve missed: the possibility for SQL injection does not mean they can output contents of the database. They can change the content but not extract data. Also, there are a lot script kiddies around that run automated scripts that are hardcoded with the ‘WP_’ prefix to check if SQL injection works.

    I agree, it doesn’t guarantee anything but no security ever will.. All you can do is put in as much fences to block an attacked that make you feel are a contribution to a safer enviroment and worth the effort. It doesn’t harm anything to change the prefix but possibly blocks some hackingactivity that otherwise would’ve been successfull…

    Anyhow 🙂 I couldn’t quite manage to get the adminmenu running when manually changing the prefix, some records also needed to be updated. In the end I installed the plugin DEFENDER which also has the option to change the databaseprefix. When I used that option all kept working with an altered databaseprefix. I never had any problem before using the Plesk option to change the prefix and the only thing not working that I could see were the custom fields…

  • You should submit this request as a new support ticket here https://support.advancedcustomfields.com/new-ticket/

    If you hit delete by mistake you can always reload the edit page. This will reload the field group as it was the last time you saved it. Save field groups often and you can always recover if you fat finger something.(Yes, I have fat fingers :P)

  • It depends on the query. All queries based base on meta_value are going to be slower. The reason for this is that the meta_value field in the DB is not an indexed field.

    The more meta values you’re searching on, the slower your query will be.

    Some types of queries are even most costly, for example “LIKE” queries on the meta_value is going to be slower than ‘=’

    There really isn’t a way to “optimize” these queries any more than what is being done. The only way to improve these is to
    1) Write your own SQL to get what you need and query the db directly instead of depending on WP
    2) Pre index the search results for each possible search and store these results for use instead of doing the query.

    On the other hand…

    If you’re talking about the queries that ACF runs when you call get_field() or one of the other functions for getting values, it depends on the type of field. There are some fields that will be slower than others.

    For example, an image field, if you have ACF set to return and array or image object, this will be slow because ACF has to do a lot of queries to build that image array. When it comes to image fields you are better off only returning the attachment ID and then using WP functions to only get what you need. The same is true of any of the fields that can return WP objects like taxonomy fields, post object fields, relationship fields. For performance you will always be better off getting the ID and then using it to call WP functions yourself. The reason is that ACF is probably getting a lot more information than you really need and doing extra queries to get this unneeded information.

    In addition to this, if you are getting values for a post that is not the current post in the loop… example:

    
    if (have_posts()) {
      while (have_posts()) {
        the_post();
        
        // now you get several values for another post
        // that is not the global $post in this loop
    
      }
    }
    

    This will add additional queries, before getting any values using get_field(), get_sub_field(), etc you might see a reduction in the number of queries performed by calling

    
    get_post_meta($other_post_id);
    

    What this does is to get all of the meta values for the other post in a single query rather than doing a query for each field. This may or may not give you an improvement, I have yet to figure out under what conditions WP does this automatically and when it does not, but if WP has already loaded all of the meta values for a post, calling the function in the manner will not create any additional queries, so it can’t really hurt.

  • This reply has been marked as private.
  • Hi Rafaromo,

    You could use this

    $args = array (
        'post_type' => 'YourPostType',
        'meta_query' => array(
    		array(
    	        'key'		=> 'start_date',
    	        'compare'	=> '=',
    	        'value'		=> $TheDateYouAreLookingFor,
    	    )
        ),
    );
    
    // get posts
    $posts = get_posts($args);

    I got this from the ACF guide: https://www.advancedcustomfields.com/resources/date-picker/

    The can also be used with the regular WP Query. The date you are looking for needs to be in the same format as the custom field date that is saved to the database.

    Hope this helps,
    Neasa

  • Hi dzulfriday,

    Did you get this ? I need same requirement. if yes, could you tell the solution.

    Appreciate your support.

    Thanks

  • I have experienced a similar issue (or at least related to caching). In a new website with the latst ACF Pro hosted in Siteground, activating their own caching plugin called SuperCacher breaks the ACF UI and all field group appear as inactive. Removing the plugin does not help, you have to also remove the object-cache.php from wp-content and delete the cache folder. I suspect the issue was because i enabled memcache but i am not 100% sure. This might be relevant to the above question

  • Checkbox fields store serialized arrays and do not store the values in standard WP meta fields that can be searched using ‘IN’.

    You need to use “LIKE”

    
    array(
      'key' => 'department',
      'value' => '"Social Work"',
      'compare' => 'LIKE',
    )
    
  • Annoyingly i’ve already deleted all my fields and check this useful thread a bit too late to read the clean on delete possibilities.

    I’ve got around 4,000 posts with a lot of dead meta.

    Couldn’t this be achieved with a bit of SQL? Trying to piece it together but not my strongest field!

    post_type=’acf-field’, post_excerpt seems to be the name of the field in this case ‘post_startdatetime’

    post_meta.meta_key is then like this
    post_startdatetime
    _post_startdatetime

    So if the post_type=’acf-field’ are deleted could we loop through the post_meta.meta_key, check if there’s a matching posts.post_excerpt and if not delete the post_meta entry?

    But there’s there’s an entry per post with a name like ‘field_534fe013d9a0d’ though we would still get 75% of unused post_meta.

  • Hi @gummi thanks for taking the time to help. I still don’t quite understand 100%. My code so far is below.

    Ideally, Im looking to pull in the previous and next title field in my loop, a long with the current loop title.

    <?php
    
    $blocks = get_field('fbs');
    
    if( $blocks ) :
    
    $count = 1;
    
    ?>
    
    <div id="fullpage">
    
    	<?php foreach( $blocks as $block ) :
    
    	// ACF Vars
    
    	$image	= $block['fb_main_image'];
    	$imagePos = $block['fb_main_image_fp'];
    
    	$title 		= $block['fb_title'];
    	$text		= $block['fb_text'];
    
    	$link 		= $block['fb_link'];
    	$linkText   = $block['fb_link_text'];
    
    	?>
    
    	<div class="section" data-anchor="section-<?php echo $count; ?>" style="background-image: url(<?php echo $image['url']; ?>);">
    
    		<section class="o-block">
    
    			<div class="o-container o-container--top">
    				<h2 class="o-type-60 u-mb-x4 u-colour-white">GET PREVIOUS TITLE HERE</h2>
    			</div>
    
    			<div class="o-container">
    
    			<h2 class="o-type-100 u-mb-x4 u-colour-white"><?php echo $title; // Current Title?></h2>
    
    			</div>
    
    <div class="o-container">
    
    			<h2 class="o-type-100 u-mb-x4 u-colour-white">GET NEXT TITLE</h2>
    
    			</div>
    </section>
    						<!-- .o-block -->
    
    					</div>
    					<!-- .section -->
    
    					<?php $count++; endforeach; ?>
    
    				</div>
    				<!-- #fullpage -->
    
    				<?php endif; ?>
  • I reworked my code to look like this and everything is working so far!

    <?php
    /**
     * Shortcode: [deptlist department=""]
     * Description: This is how stuff works with parameters
     */
    
    function dept_option($atts){
    	
    	extract(shortcode_atts( array(
    		'department' => 'Legal Studies',
    	
    	), $atts ));
    	$myfinalcode = '"' . $department . '"';
    	
    	$args1 = array(
    		'meta_key' => 'last_name',
    		'orderby' => 'meta_value',
    		'order' => 'ASC',
    		'exclude' => array(1,8,9),
    		'meta_query' => array(
    			'relation' => 'AND',
    			'department' => array(
    				'key' => 'department',
    				'value' => $myfinalcode, 
    				'compare' => 'LIKE',
    			),
    		)
    	);
    	$subscribers = get_users($args1);
    		echo '<ul>';
     			foreach ($subscribers as $user) {
     			echo '<li>' . $user->display_name.' ['.$user->phone_number . ']</li>';
     			}
    		echo '</ul>';
    	
    // ENDING ROW	
    }
    add_shortcode( 'deptlist', 'dept_option' );
    ?>
  • And again, I solved it on my own ^^.
    I ended up with simple input fields.

    If anyone is interested in it, here is my admin.js code and a screencast gif:

    (function($){
        'use strict';
        acf.add_action('append', function( $el ){
            var layout = $el.attr('data-layout');
            if( layout === null || typeof layout === 'undefined') return;
            if( layout && layout.indexOf('_product') === -1 ) return;
    
            var $productAttributes = acf.get_field('', jQuery('.values [data-name="product_attributes"]'));
            var attributes = $productAttributes.find('textarea').val();
    
            $.each( attributes.split(/\n/),  function ( i, attr ) {
                $el.find('a[data-event="add-row"]').last().trigger('click');
                var name_input = $el.find('tr.acf-row:not(.acf-clone) [data-name="attribute_name"] input');
                name_input.last().val(attr);
                //name_input.prop('disabled', true); //not storing in db
            });
    
        });
    })(jQuery);

    Screencast

  • @kristincodeswp Thanks for the nudge in the right direction. The admin only fields will work perfectly for my requirement.

  • When you append the query like that, it becomes another level deep, which is not what you want.

    
    ...
    [relation] => OR
    [0] => Array (
        [0] => Array (
            [key] => circles
            [value] => 67
            [compare] => LIKE
        ),
        [1] => Array (
            [key] => circles
            [value] => 62
            [compare] => LIKE
        )
    )
    

    Try to use array merge to merge them, something like:

    
    'meta_query' => array(
        'relation' => 'AND',
        array(
            'key'     => 'file_type',
            'value'   => 'circle',
            'compare' => '=',
        ),
        array_merge(array('relation' => 'OR'), $circleRelations)
    ),
    

    Cheers.

  • For anyone that runs across this, @elliot’s custom filter to allow the LIKE function to work no longer works as of WP 4.8.3

    If you replace it with the following function you’ll be all set. Hopefully this saves someone else the few hours I lost on it 🙂

    function allow_wildcards( $where ) {
    global $wpdb;
    $where = str_replace(
    "meta_key = '{$repeater_field_name}_%_{$sub_field_name}", 
    "meta_key LIKE '{$repeater_field_name}_%_{$sub_field_name}",
    $wpdb->remove_placeholder_escape($where)
    );
    return $where;
    }
    
    add_filter('posts_where', 'allow_wildcards');
  • Hi,

    If you are doing a secondary on a page, you’d need to pass the pagination argument into your WP_Query.

    https://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters

    
    $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
    $query = new WP_Query( array( 'paged' => $paged ) );
    

    Cheers.

  • @cultivate

    Hi, sorry no I didn’t. The project changed direction and no longer required it. However, if you come up with a solution I would like to know 🙂

  • Hi all,

    This has been really useful for me. I’ve been trying to find a way to use an ACF field as a CPT title and this works nicely for me

    `* add custom slug and title */

    function my_post_title_updater( $post_id ) {

    if ( get_post_type( $post_id ) == ‘venue’ ) {

    $my_post = array();
    $my_post[‘ID’] = $post_id;
    $my_post[‘post_title’] = get_field( ‘venue_name’, $post_id );

    wp_update_post( $my_post );

    }

    }

    // run after ACF saves the $_POST[‘fields’] data
    add_action(‘acf/save_post’, ‘my_post_title_updater’, 20);

    A couple of quick questions …

    How can I concatenate two variables so that I can use ‘venue_name’ and ‘venue_city’?

    Also, how can I expand this to update the slug to use the same title ‘venue_name’ and ‘venue_city’? I currently have http://localhost:8888/gigs/venue/auto-draft/ as the slug.

    Thanks all.

    Cheers

    Phil

  • So, your field’s return type is set to object, that’s is why your condition is always false. Because an object will not equal to a string.

    If you wanna check the condition by the post title, you try something like:

    
    $post_object = get_field('obits-second_visitation_location');
    
    if (! $post_object || $post_object->post_title != 'Announcement Pending'):
        ......
    

    Cheers.

  • Thanks, @gummiforweb; here’s the var_dump:
    object(WP_Post)#3438 (24) { ["ID"]=> int(96) ["post_author"]=> string(1) "4" ["post_date"]=> string(19) "2017-10-18 19:44:55" ["post_date_gmt"]=> string(19) "2017-10-18 19:44:55" ["post_content"]=> string(0) "" ["post_title"]=> string(20) "Announcement Pending" ["post_excerpt"]=> string(0) "" ["post_status"]=> string(7) "publish" ["comment_status"]=> string(6) "closed" ["ping_status"]=> string(6) "closed" ["post_password"]=> string(0) "" ["post_name"]=> string(10) "pendingtba" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2017-10-18 19:45:44" ["post_modified_gmt"]=> string(19) "2017-10-18 19:45:44" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(58) "http://mytestingdomain.com/?post_type=location&p=96" ["menu_order"]=> int(0) ["post_type"]=> string(8) "location" ["post_mime_type"]=> string(0) "" ["comment_count"]=> string(1) "0" ["filter"]=> string(3) "raw" }

    I see lots of stuff and honestly, I don’t really know what I’m looking for, but perhaps it’s no coincidence that the first thing in the list is the post number and id? That said, I do see the post title is showing correctly, so maybe instead of get_field I should try something that check’s the post title or ID?

    Actually that doesn’t make sense either, since I’m trying to use the post_object field on this post to figure out which related location post to pull info from. In other words, I can’t grab the post_title until I know which title I’m supposed to be looking for. Unless I’m missing something…Like I said before, I’m still pretty green with these PHP thingies so I certainly appreciate any help sorting through my mess here!

  • Have you checked the video that I send to you? I use the same sting as in the docs and it doenst work on the video.
    https://monosnap.com/file/fkJQq8jz9ctsOmEXt3MPujP7wtcKKy.png

  • Hi @rasso & @danielrutkowski,

    I have used your code to do some tests and I finally modify it to limit the number of Ajax call :

    
    	acf.do_action('ready', $('body'));
    
        $('.acf-form').on('submit', function(e){
            e.preventDefault();
        });
    
    	acf.add_action('submit', function($form){
    		$.ajax({
    			url: window.location.href,
    			method: 'post',
    			data: $form.serialize(),
    			success: function(data) {
    				acf.validation.toggle($form, 'unlock');
                    alert(data);
    			}
    		});
    	});
    

    In the actual code the AJAX success has no response data. If you want to get the “update message” set in the form declaration you can use this hook :

    
    add_action('acf/submit_form', 'my_acf_submit_form', 10, 2);
    function my_acf_submit_form( $form, $post_id ) {
    
        if(is_admin())
            return;
    
        //Test if it's a AJAX request.
        if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
            echo $form['updated_message'];
            die();
        }
    
    }

    I hope this code can help you! 😉

  • OK so this was actually due to a conflict with the Posts Types Order plugin, the query works as expected.

  • As described above, fields hidden by conditional logic are not submitted or updated. I didn’t build ACF and I can’t say if this will change, I just know the way it works and I don’t expect it to change.

    You would need to submit a support request to get the developer’s input and that can be done here https://support.advancedcustomfields.com/new-ticket/.

    If you want to use conditional logic for some other purpose than having conditional values then you need to look at some other way of doing this. For example, building custom JavaScript that will hide and show fields in some other way than using the built in condition logic functionality of ACF. You could hide and show fields in some other way that would allow the values of the fields to be submitted.

  • You are talking about a “Group Field” and not a “Field Group”.

    A “Group Field” in all aspects is a repeater field that always has exactly 1 row. Updating a group field would follow the same rules as updating a repeater or a sub field.

    This is why trying to update the “sub field” is not working correctly when using update_field().

    You need to look at the sections here about working with repeaters and sub fields.

    This can be done by providing the entire group field array in the update, for example.

    
    $value = array(
      // nested array for row
      // field key => value pairs
      'field_123456' => 'sub field 1 value',
      'field_654321' => 'sub field 2 value',
      // etc
    );
    // update the "group field"
    update_field('field_000000', $value);
    
Viewing 25 results - 10,451 through 10,475 (of 21,363 total)