Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • You want to create searching and filtering on an acf field. For this see the section titled

    Dynamic $_GET parameters

    on this page

    https://www.advancedcustomfields.com/resources/query-posts-custom-fields/

  • @jgregory we did not figure out a solid migration plan. We found a work around, although I think there should be a better solution, of publishing our clone fields and renaming them the same name as the existing cloned field name. This allowed us to keep the data intact.

    So basically, we had several Field Groups that were a tab layout. To keep the data and have then show in GraphQL, we had to get the existing name of the clone field in the tab, publish the field being used for cloning and rename it to what the field name was in the tab.

    I did come up with some sort of db migration, but it got confusing and I wasn’t the only one working on the project so we ended up scrapping it and going this way, but here is what I came up with if you wanted to go the go the db route.

    For example, to search for Header Secondary you would use:

    SELECT * FROMwp_postmetaWHERE meta_key like '%_header_secondary%'

    this will return all keys for that. But we still need to find the specific one for the field group you are working on. To do that we need to find a post that is using that group and get it’s ID and then we can run:

    SELECT * FROMwp_postmetaWHERE post_id = {id} AND meta_key like '%header_secondary%'

    Now that you have both key and value for a post we can run an update sql statement. There will be 2:

    We are migrating old field name to new field
    UPDATEwp_postmeta` as m
    JOIN wp_posts as p ON m.post_id = p.ID
    SET m.meta_key = ‘new_field_name’
    WHERE m.meta_key = ‘old_field_name’
    AND p.post_type = ‘page’`

    We are migrating old field value to new field name.

    This is how we keep the data this is what is mapped to the wp_posts table
    UPDATE <code>wp_postmeta</code> as m 
    JOIN <code>wp_posts</code> as p ON m.post_id = p.ID 
    SET m.meta_key = '_new_field_name' 
    WHERE m.meta_value = 'field_5af0d933478b4' 
    AND p.post_type = 'page'

    I did run some tests with this and it did work. Depending on how many Fields you have though this could be a long process. I was thinking about maybe righting up a php script that could automate this but I don’t have much time to work on it.

  • Maybe this might help someone, I’m attaching my configuration for a link-button. It offers variations for internal, external and on-page (anchor) links.

    Also, this is a function to output a link:

    function nij_output_link($atts, $class = '') {
    	if (!empty($atts)) {
    		return;
    	}
    
    	$type = $atts['link_type'] ?? 'internal';
    
    	$url = '';
    	switch ($type) {
    		case 'internal' :
    			if (is_numeric($atts['link_' . $type])) {
    				// this is a post id and should be converted to a link
    				$url = get_permalink($atts['link_' . $type]);
    			} else {
    				// this is an archive link (and it should be left untouched)
    				$url = $atts['link_' . $type];
    			}
    			break;
    
    		case 'external' :
    			$url = $atts['link_' . $type];
    			break;
    
    		case 'onpage' :
    			$url = '#' . $atts['link_' . $type];
    			break;
    	}
    
    	$target = $atts['link_target'] ?? '_self';
    
    	$text = $atts['link_text'] ?: (($type == 'internal') ? get_the_title($atts['link_internal']) : '');
    	$class = $class ?: '';
    
    	if (is_admin() && !empty($text)) {
    		$text = __('Knoptekst niet ingevuld', 'nijstartertheme');
    		$class .= ' disabled';
    	}
    
    	return "<a href='{$url}' class='{$class}' target='{$target}'>{$text}</a>";
    }
  • Students often find it difficult to apply the knowledge thus received in the assignments. Improper comprehension leads to inadequate use of resources which as a result influences the grade negatively. MYOB Assignment Help have a thorough knowledge and experience about assignments and their specific requirements.

  • John Huebner

    I mean could you present a quotation for that job?

  • Here is the new code with meta_query, but same result.
    Any idea on what I’m missing ?

    
    add_action( 'pre_get_posts', 'films_query' );
    function films_query( $query ) {
      if ( !is_admin() && $query->is_main_query() && is_post_type_archive( 'films' ) ) {
        $cat_hide = get_field('categorie_des_films_a_masquer', 'options');
        $taxquery = array(
          array(
            'taxonomy' => 'categorie_films',
            'field' => 'term_id',
            'terms'    => $cat_hide,
            'operator' => 'NOT IN',
          )
        );
        $query->set( 'posts_per_page', '-1' );
        $query->set( 'post_status', 'publish' );
        $query->set( 'tax_query', $taxquery );
        $query->set( 'meta_query', array(
          'relation' => 'AND',
          'date' => array(
            'key' => 'date_de_sortie',
            'compare' => 'EXISTS',
            )
          )
        );
        $query->set( 'orderby', array(
          'date' => 'ASC',
          'title'   => 'ASC',
          )
        );
      }
    }
    
  • Here is the new code with meta_query but same results.
    There is something I don’t understand…

    
    add_action( 'pre_get_posts', 'films_query' );
    function films_query( $query ) {
      if ( !is_admin() && $query->is_main_query() && is_post_type_archive( 'films' ) ) {
        $cat_hide = get_field('categorie_des_films_a_masquer', 'options');
        $taxquery = array(
          array(
            'taxonomy' => 'categorie_films',
            'field' => 'term_id',
            'terms'    => $cat_hide,
            'operator' => 'NOT IN',
          )
        );
        $query->set( 'posts_per_page', '-1' );
        $query->set( 'post_status', 'publish' );
        $query->set( 'tax_query', $taxquery );
        $query->set( 'meta_query', array(
          'relation' => 'AND',
          'date' => array(
            'key' => 'date_de_sortie',
            'compare' => 'EXISTS',
          )
        )
      );
      $query->set( 'orderby', array(
        'date' => 'ASC',
        'title'   => 'ASC',
      )
    );
    }
    }
    
  • Here is with meta_query args but it didn’t work, I have the same results.
    There is something I don’t understands.

    
    add_action( 'pre_get_posts', 'films_query' );
    function films_query( $query ) {
      if ( !is_admin() && $query->is_main_query() && is_post_type_archive( 'films' ) ) {
        $cat_hide = get_field('categorie_des_films_a_masquer', 'options');
        $taxquery = array(
          array(
            'taxonomy' => 'categorie_films',
            'field' => 'term_id',
            'terms'    => $cat_hide,
            'operator' => 'NOT IN',
          )
        );
    
        $query->set( 'posts_per_page', '-1' );
        $query->set( 'post_status', 'publish' );
    
        $query->set( 'tax_query', $taxquery );
        $query->set( 'meta_query', array(
          'relation' => 'AND',
          'date' => array(
            'key' => 'date_de_sortie',
            'compare' => 'EXISTS',
          )
        )
      );
      $query->set( 'orderby', array(
        'date' => 'ASC',
        'title'   => 'ASC',
      )
    );
    }
    }
    
  • This is not something I would do with an ACF field or something that I would store anywhere. These are calculations that I would do only when the value needs to be displayed. The reason you would not store it is that every time a post is added or a post is updated the value of each calculated field for every post would need to be recalculated.

    To do the calculation on the fly using only what is provided in WP and ACF and not adding a lot of extra coding work would mean doing a query to get all the posts (athletes), looping over them and getting the field values, adding them up and then dividing by the total number of posts and then comparing. This would have to be done every time. This would create a significant performance issue if you tried doing it on multiple values. With 1000+ posts this would more than likely time out the loading of a page.

    If you want to have this is a field then it would need to be done every time the profile is loaded. If you want the value to update when a field is changed then it would mean adding ajax to do the calculations every time a field is changed.

    To improve performance you could create a WP Option that holds the values for every athlete in an array. This option would be updated whenever an athlete is added/updated/deleted. Again, if you want to have anything happen when a value is changed instead of after saving you would need to add AJAX that updates the option value and performs the calculation.

    Overall, doing something like this with all statistics for each athlete would be a large project, even if you exclude the AJAX.

  • If you want to sort by an acf field and something else then you must use a meta query with clauses.

    See the code example labeled
    ‘orderby’ with multiple ‘meta_key’s

    https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters

    the difference here that you would use post_title for the second part of the order by instead of 2 meta clauses.

  • I found out that the select2 can be refreshed by calling the change.select2.

    
    var field = acf.getField('acf-field-key');
    var $select = field.$el.find('select');
    
    // Could also be jQuery collection, optgroup elements or HTML string if working
    const newOptions = [
        new Option('New label', 'new-value'),
        new Option('Another option', 'another-value')
    ];
    
    // Clear previous elements
    $select.empty();
    
    // Add new options to select element
    $select.append(newOptions);
    
    // Set a new selected option
    $select.val('new-value');
    
    // Refresh select2
    $select.trigger('change.select2');
    

    You can of course keep or alter previous elements, instead of removing them. I guess you could do pretty much anything before triggering the change.select2 event.

    I hope the JavaScript API will update in the future to a non jQuery solution

  • Hi @awaisqarni576, If you want to convert of a particular website. Then you should follow some steps:
    Download your site’s XML file

      Create a WordPress account
      Import your XML file
      Move your domain
      Import theme
      Add plugins

    If you any other query then connect with us: https://www.zyplesoft.com/ Thanks!

  • @hube2 update, I just copied the HTML being generated for these fields https://share.cleanshot.com/5cWX8j is over 134000 lines (see: https://share.cleanshot.com/W3uG3X) – could that be the main reason of the problem?

    UPDATE:

    I also see that the clone fields HTML is actually being generated on the page here: https://share.cleanshot.com/b0hqeA – is that normal? Isn’t there a way that this HTML is only generated when you actually add the layout?

  • @hube2 I’m facing a similar challenge so I am posting my question here rather than opening a new thread.

    I am building a new using Flexible Content + Repeater Field. This is an example of the edit screen: https://share.cleanshot.com/5cWX8j. So we have a repeater field that holds the flexible content. The reason for using the repeater field is to act as a container wrapper in case the client wants to customize colors, backgrounds, etc. Then each of the sub section also has those similar options.

    I am also extensively using “clone” field so all the layouts in flexible content are cloned in different groups like this: https://share.cleanshot.com/FWZjcI

    While this is working perfectly in terms of functionality, I am facing a performance issue on the edit screen. It takes around 20 to 40 seconds to load the fields. However, once it’s loaded, I can easily edit the fields. The problem with this is that it becomes hard for me as well as the client to be able to edit something quickly.

    Is there anything I can do to improve the performance in some way? In the past, I know that when I didn’t wrap the repeater field around the flexible content, it worked better. However, that repeater field is quite important for styling and functionality part.

    Any help or right direction would be appreciated.

  • This reply has been marked as private.
  • Correction, I pasted in the wrong query above.

    The query

    
    select
    	p.ID,
    	p.post_title, 
    	pm.meta_value
    from wp_posts p
    inner join wp_postmeta pm on pm.post_id = p.ID
    where pm.meta_key = 'campaign_end_date'
    and p.post_status = 'publish'
    order by pm.meta_value asc
    

    The data

    
    257867	Barbaric	20220906
    257863	River Trek	20220909
    257396	Comic Book Bubble	20220913
    257405	Sea of Legends: Vengeance of the Empires	20220915
    257873	RoboMon	20220916
    257398	Trailblazers	20220916
    257865	Full Sun	20220917
    257864	Bakufu: A Japanese Themed Strategic Card Game	20220920
    257866	Diamond Dig	20220920
    257874	Honey	20220920
    257406	Almost Innocent	20220920
    257868	Dwar7s Legendary Forest	20220921
    257404	Kinfire Chronicles: Nights Fall	20220921
    257403	CobbleCritters	20220922
    257869	The FOG - Escape from Paradise	20220922
    257862	Weavlings in the Wilds	20220929
    
  • Only problem now is i have to go into every single post, click edit and save or the title is just “(no title)”.
    If i try to do this via quick edit, it doesnt update either.
    Any solution to this anyone?

  • I was probably doing something wrong before, because I’ve tried again with the add_attachment action and this time I was successful.

    function do_stuff_to_the_uploaded_attachment( $attachment_ID ) {
    
        global $MY_ENDPOINT;
        //$user_id = get_current_user_id();
    
        if ( ! current_user_can( 'upload_files' ) ) {
            return;
        }
    
        $args = array( 
            'ID'           => $attachment_ID, 
            //'post_title' => 'My default title ...', 
            'post_excerpt' => 'My default caption ...', 
            'post_content' => $_SERVER[ 'HTTP_REFERER' ], 
        );
        // Use the Title, Caption and Description,
        // to output/diagnose the referer and other data.
        wp_update_post( $args );
    
        /**
         * If the request came from the specific URL, then do stuff to the attachment.
         * 
         * Note: Ideally we'd target the "Add Media" button itself,
         * but since there doesn't seem to be anything identifiable about it,
         * we're targeting the URL of its page.
         */
        if ( strpos( $_SERVER[ 'HTTP_REFERER' ], $MY_ENDPOINT ) !== false ) {
            // Do stuff to the attachment by using its ID i.e. $attachment_ID
        }
    }
    add_action( 'add_attachment', 'do_stuff_to_the_uploaded_attachment', 10, 1 );
  • For anyone interested, i managed an easy css fix that required none of the above.

    this to the style sheet:

    .et_pb_social_media_follow .icon[href=””] {
    display: none;
    }

  • Hi there,

    Honestly, I don’t remember exactly what I did, but this code works now (I might have had to recreate the fields)

    <?php
    $my_current_lang = apply_filters( ‘wpml_current_language’, null );
    // $queried_object = get_queried_object();
    // var_dump( $queried_object );
    ?>

    <?php
    
    		$loop = new WP_Query(
    			array(
    				'post_type' => 'page',
    				'post__in'  => array( 21 ),
    			)
    		);
    		?>
    <?php
    while ( $loop->have_posts() ) :
    	$loop->the_post();
    	$rolunkbg   = get_field( 'aboutus_bg' );
    	$rolunktext = get_field( 'aboutus_text' );
    
    	?>
    
    <div class="container-fluid bg1 slanted2" style=" background-image:url('<?php echo wp_get_attachment_url( $rolunkbg ); ?>">
        <div class="container tagline">
    
            <h4 class="tagline--description"><?php echo $rolunktext; ?></h4>
    
            <?php endwhile; ?>
            <!-- ;" width="45"> -->
    
            <h2 class="tagline--h2 tagline--transparent">
                <?php
    			if ( $my_current_lang == 'en' ) {
    
    				?>
                <!-- ABOUT US -->
                <?php
    			} else {
    				?>
                <!-- Rólunk -->
                <?php
    			}
    			?>
            </h2>
            <h3 class="tagline--subheadline pt-2 text-center">
                <?php
    			if ( $my_current_lang == 'en' ) {
    				?>
                A professzionális audiovizuális megoldások forrása.
                <?php
    			} else {
    				?>
                A professzionális audiovizuális megoldások forrása.
                <?php
    			}
    			?>
            </h3>
            <h2 class="tagline--h2">
                <?php
    			if ( $my_current_lang == 'en' ) {
    				?>
                <!-- ABOUT US -->
                <?php
    			} else {
    				?>
                <!-- Rólunk -->
                <?php
    			}
    			?>
            </h2>
    
            <?php if ( $my_current_lang == 'en' ) { ?>
            <div class="row">
                <div class="col-3"></div>
                <div class="col-6"><a href="about">
                        <div class="btn-primary text-center">About us</div>
                    </a></div>
                <div class="col-3"></div>
            </div>
            <?php } ?>
    
            <?php if ( $my_current_lang == 'hu' ) { ?>
            <div class="row">
                <div class="col-3"></div>
                <div class="col-6"><a href="rolunk">
                        <div class="btn-primary text-center">Rólunk</div>
                    </a></div>
                <div class="col-3"></div>
            </div>
            <?php } ?>
        </div>
    </div>

    Let me know if it does not help and I’ll check if I needed to change something with the fields in admin.

  • Helle there,

    How do we make a new loop query for ACF in the Divi code module?
    I would like to bring in a field code addon to ACF.

    thanks

    Pablo

  • You will need to add custom JS to ACF. You will need to add a JS action that fires when the field changes. In this action you will need to make an AJAX request to get the value from the selected CPT and then update the text/number field.

    Targeting a sibling to update in a repeater based on the field that was changed

    
    // field_XXXXXX represents field to be updated
    // {INPUT TYPE} represents the field type of the actual field you will be updating
    field.closest('.acf-row').find('[data-key="field_XXXXXX'] .acf-input {INPUT TYPE}');
    
  • It depends on if you will use basic post data or not. When you get the field, if you get posts then the posts will be cached when ACF does get_posts(). if you are not going to use post data then it is more efficient to use IDs. If you use IDs you can always do your own query to get the posts if you need them.

  • You can run a query for the unique_id with the below:

    
    $existingPost = get_posts( array(
        'meta_key'   => 'unique_id',
        'meta_value' => '555555',
    ));
    
    if($existingPost){
        $my_post['ID'] = $existingPost->ID;
        $post_id = wp_update_post( $my_post );
    }else{
        $post_id = wp_insert_post( $my_post );
    }
  • In case anybody else finds this, I had the same issue when displaying an image as a background image. I was using something like:

    <?php if ($photo) { echo 'background-image: url("' . esc_url($photo['url']) . '");'; } ?>">

    Turns out the double quotes within the url(“”) caused the file name to output without slashes. I believe that’s valid CSS but I guess PHP doesn’t like it. Solved it by removing the double quotes:

    <?php if ($photo) { echo 'background-image: url(' . esc_url($photo['url']) . ');'; } ?>">

    Or by using single (escaped) quotes:

    <?php if ($photo) { echo 'background-image: url(\'' . esc_url($photo['url']) . '\');'; } ?>">

Viewing 25 results - 4,101 through 4,125 (of 21,340 total)