Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • I’m not sure what other details I can go into.

    To get the dynamic style sheet you are actually calling on WP’s AJAX request script https://codex.wordpress.org/AJAX_in_Plugins, this is what you are enqueuing. The action=some_action part of the URL tells WP what hook to run.

    You create an action filter and this action filter outputs the CSS, this can be done by either outputting it directly in the function or by including a separate PHP file that does the CSS. This would all look like a CSS file except for the dynamic parts that would be PHP.

    The only thing that’s not included in the link I provided or in the documentation is that before you start outputting the CSS that you need to indicate that what is returned is in fact CSS. To do this, before outputting CSS you do

    
    <?php header("Content-type: text/css"); ?>
    
  • @JohnHuebner
    Any chance you can go into more detail? I am new to WP development. I read through the link you reference and have read several other sources online but I can’t quite put it together.

    Thank you,

  • Ok, I added those line in wp-config.php:

    // Enable WP_DEBUG mode
    define( 'WP_DEBUG', true );
    
    // Enable Debug logging to the /wp-content/debug.log file
    define( 'WP_DEBUG_LOG', true );
    
    // Disable display of errors and warnings
    define( 'WP_DEBUG_DISPLAY', false );
    @ini_set( 'display_errors', 0 );

    I can see it’s working because the debug.log was created and is being filled with error messages.

    I added your error_log snippet directly under the function start:

    function my_taxonomy_query( $args, $field, $post_id ) {
      error_log('My Filter Was Called');
        // modify args
        $args['orderby'] = 'count';
        $args['order'] = 'ASC';
        $args['include'] = '589,186'; // list of terms to include
        // return
        return $args;
        }
    add_filter('acf/fields/taxonomy/query/name=ti_tag_test', 'my_taxonomy_query', 10, 3 );

    Not sure about this position though.

    So far, nothing like ‘My Filter Was Called’ in the error_log.

  • So the first thing you need to do is figure out if your filter is actually being called, which is a little complicated since it in a AJAX request.

    The first thing you need to to is turn on error logging https://codex.wordpress.org/WP_DEBUG

    Then at the top of the function you can output stuff to the error log, for example if you just want to see if the filter is called

    
    error_log('My Filter Was Called');
    

    Then you can look in the error log to see if that appears and that will tell you if the filter is called or not.

  • I’m on a dead-end here. I noticed from another coding issue that I should define the variables written in the function ($args, $field, $post_id). Post ID is clear what to do with it, but I’m not sure if and with what I should define $args and $fields. I have no idea what $fields relates to at all.

    $post_id = get_the_ID();
    function my_taxonomy_query( $args, $field, $post_id ) {
        // modify args
        $args['orderby'] = 'count';
        $args['order'] = 'ASC';
        $args['include'] = '589,186'; // list of terms to include
        // return
        return $args;
        }
    add_filter('acf/fields/taxonomy/query/name=ti_tag_test', 'my_taxonomy_query', 10, 3 );
  • Blast from the past — @animalejourbano + anyone who needs it:

    As @elliot mentioned, pop something like this somewhere (page template) where you can load it on the front end.

    Required: Replace YOURCUSTOMPOSTTYPE and YOURCUSTOMFIELD

    Optionally use $custom_field_raw if you’d like to maintain any formatting in your custom field.

    <?php
    
    global $post;
    $args = array( 
    	'post_type' => 'YOURCUSTOMPOSTTYPE', 
    	'posts_per_page' => -1,
    	'post_status' => 'any'
    );
    
    $myposts = get_posts( $args );
    foreach ( $myposts as $post ) : setup_postdata( $post );
    
    	$custom_field_raw = get_field('YOURCUSTOMFIELD');
    	$custom_field_text_only = wp_strip_all_tags($custom_field_raw);
    
    	$my_post = array(
    		'ID'           => get_the_ID(),
    		'post_content' => $custom_field_text_only // use $custom_field_raw if you want to keep any HTML formatting
    	);
    
    	wp_update_post( $my_post );
    
    endforeach; 
    wp_reset_postdata();
    
    ?>

    Hope this helps someone, someday 🙂


    mp

  • It would be something like this

    
    [acf field="field_name" post_id="term_1"] // 1 is the term ID
    
  • Where

    $uniqueid = uniqid('faq_items');

    sets a variable by pulling the ACF unique ID of a repeater in a flex block called faq_items

    and

    <div id="collapse-<?php echo esc_attr( $uniqueid ); ?>-<?php echo esc_attr( $count ); ?>

    echos that out in the frontend and also increments the repeater rows.

  • Just an FYI for more advanced usage cases, for example where you have multiple repeaters on the same page in flexible content and you need unique ID’s for each block(for example to target bootstrap modals or collapse elements) you can do something like this:

    <section class="faq-block <?php if (get_sub_field('background') == 'blue'): ?> blue-bg<?php else: ?><?php endif; ?>">
        <div class="container">
            <div class="row text-center">
                <div class="col-md-10 col-md-offset-1">
    
                    <h2 class="section-heading"><?php the_sub_field( 'section_heading' ) ?></h2>
    
                    <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
                       <?php
                       //$uniqueid = get_sub_field( 'faq_unique_id' );
                       $uniqueid = uniqid('faq_items');
                       $count = 0;
                       while ( have_rows( 'faq_items' ) ) : the_row(); ?>
                       <div class="panel panel-default listbox">
                        <div class="panel-heading" role="tab" id="headingTwo">
                            <h3 class="panel-title">
                                <a data-toggle="collapse" data-parent="#accordion"
                                href="#collapse-<?php echo esc_attr( $uniqueid ); ?>-<?php echo esc_attr( $count ); ?>"
                                aria-expanded="false">
                                <?php the_sub_field( 'faq_question' ) ?>
                            </a>
                        </h3>
                    </div>
                    <div id="collapse-<?php echo esc_attr( $uniqueid ); ?>-<?php echo esc_attr( $count ); ?>"
                        class="panel-collapse collapse" role="tabpanel">
                       <div class="panel-body">
                        <p><?php the_sub_field( 'faq_answer' ) ?></p>
                    </div>
                </div>
            </div>
            <?php $count ++; ?>
    
        <?php endwhile; ?>
    
    </div><!--end panel group-->
    
    </div>
    </div>
    </div>
    </section>
  • Beautiful, I knew it was something simple that I was missing. I took your example and tweaked it so that if the user only inputs a single color, it’ll fall back to background-color rather than background-image for the gradient. Thanks for your help! Much appreciated! 🙂

    
    <?php 
    if( have_rows('bike_listing-color') ) { //Bike color bar
    $colors = array(); 
    ?>
    <div class="colorbar" id="colorbar-<?php the_ID(); ?>"></div> 
    <?php 
    while (have_rows('bike_listing-color')) {
      the_row();
      $colors[] = get_sub_field('color');
      $count = count($colors);
    } 
    if ( $count > 1 ) { ?>
    <style>
      #colorbar-<?php the_ID(); ?>{
        background-image: linear-gradient(to right, <?php echo implode(', ', $colors); ?>);
      }
    </style>
    <?php } else { ?>
    <style>
      #colorbar-<?php the_ID(); ?>{
        background-color: <?php echo implode($colors); ?>;
      }
    </style>
    <?php } ?>
    <?php } // End if have_rows ?> 
    
  • Yup, you can definitely utilize similar conditional logic. The only thing that might affect it is that the size of your GIF could be way off from the size of the other images so you might need to regular that on the ACF upload end to make sure your user is uploading something of similar width/height.

    <?php
    $images = get_field( 'gallery' );
    $size = 'thumbnail';
    
    if ( $images ) : ?>
         <ul>
    
         <?php foreach ( $images as $image ) :
    			
         $url = $image["filename"];
         $filetype = wp_check_filetype( $url );
    
    	if ( 'gif' == $filetype['ext'] ) {
    		$url = $image['url'];
    	} else {
    		$url = $image['sizes'][$size];
    	} ?>
              <li><img src="<?php echo esc_url( $url ); ?>" alt="Text describing my image here" /></li>
         
         <?php endforeach; ?>
         
         </ul>
    <?php endif; ?>
  • How do you include your styles in the page? it doesn’t work in the style.css but you can implement custom styles by using a styles.php like this:

    function my_dymanic_styles(){
      $about_color = get_field('about_color', 'options');
    
      $custom_css = "
        a{ color:{$about_color};}
      ";
      
       return my_css_strip_whitespace($custom_css);
    }

    Put this in your functions.php

    function my_css_strip_whitespace($css){
    	  $replace = array(
    	    "#/\*.*?\*/#s" => "",  // Strip C style comments.
    	    "#\s\s+#"      => " ", // Strip excess whitespace.
    	  );
    	  $search = array_keys($replace);
    	  $css = preg_replace($search, $replace, $css);
    
    	  $replace = array(
    	    ": "  => ":",
    	    "; "  => ";",
    	    " {"  => "{",
    	    " }"  => "}",
    	    ", "  => ",",
    	    "{ "  => "{",
    	    ";}"  => "}", // Strip optional semicolons.
    	    ",\n" => ",", // Don't wrap multiple selectors.
    	    "\n}" => "}", // Don't wrap closing braces.
    	    "} "  => "}\n", // Put each rule on it's own line.
    	  );
    	  $search = array_keys($replace);
    	  $css = str_replace($search, $replace, $css);
    
    	  return trim($css);
    }
    /**
     * Dynamic Styles additions.
     */
    require get_template_directory() . '/inc/style.php'; //make sure you correct the directory and file path you use
  • Ahhh I got it working with:

    <img src="<?php the_field('footer_1_1', 3061); ?>" />

    I think I had a character issue on my keyboard (always switches languages randomly)

    Thank you so much for solving this!

  • I just copied your code and added the post id bit. Looks like there’s some things missing

    
    <img src="<?php the_field('footer_1_1', $post_id); ?>" />
    
  • <img src="<?php the_field('footer_1_1', 3061 ); ? />" />

    Gives me a syntax error:

    Parse error: syntax error, unexpected '?' in F:\wamp64\www\esprit\wp-content\plugins\php-code-widget\execphp.php(27) : eval()'d code on line 3

  • Sorry, I thought this was for the link field and not the page link field.

    The page link field doesn’t return link text and only returns the URL and you’d need to supply the text some other way.

    
    $link = get_field('your_link_field_name');
    if ($link) {
      echo '<a href="'.$link.'"><span>Button text</span></a>';
    }
    
  • You need to know the post ID of the post where the image is saved.

    From your description I’m not sure how you’d go about getting that ID.

    You then tell ACF where to get the value from

    
    <img src="<?php the_field('footer_1_1', $post_id); ? />" />
    
  • Oh wow. The mention of The Loop is definitely my issue.

    The location is “if Post equal to Footer Logo” (my custom post type)

    I am actually trying the pull the field data from inside of a PHP widget (located in my footer).

    Now that you have mentioned The Loop I realize how silly this is. I’m a beginner, forgive me.

    How can I go about calling the field from a location such as a footer widget?

  • Watermarking PDFs is not something that ACF can do for you, or even a WP specific question. You will need to find a plugin that will do this watermarking and I don’t know if such a plugin exists or not.

  • Sorry, should have been more clear. I need more information on the field/field group. Where do the location rules say the field group appears. Where in the code of your template are you trying to get the value? For that matter, what type of template are you trying to get the value in (archive? single?)?

    Is the field where you add the image on a post editor page for his custom post type?

    If it is, is the call <img src="<?php the_field('footer_1_1'); ? />" /> inside “The Loop”

  • 
    $link = get_field('your_link_field_name');
    if ($link) {
      echo '<a href="'.$link['url'].'"><span>'.$link['title'].'</span></a>';
    }
    

    https://www.advancedcustomfields.com/resources/link/

  • Hmm, the wysiwyg editor is really hard to grab. To your code I’ve added the following, as the above method of getting the ID of the wysiwyg did not work, and apparently, when the wysiwyg is there, the textarea is not (and vice-versa):

    
    	var $fields = $el.find('.acf-field').each(function(index, element) {
    		console.log('---');
    		var $type = $(element).data('type');
    		if ($type == 'group') {return;}
    		console.log('type:' + $type);
    		var $key = $(element).data('key');
    		var $val = $('input[name*=' +$key ).val();
    		if ($type == 'wysiwyg') {
    			console.log('looking for wysiwyg');
    			// does not work:
    			// var $id = $('[data-key="' + $key + '"].acf-input textarea').attr('id');
    			var $id = $(element).find('.acf-input div').attr('id');
    //something similar; we have to trim the -wrap suffic and the wp- prefix:
    			$id = $id.replace('-wrap','');
    			$id = $id.replace('wp-acf','acf');
    			console.log('id' + $id);
    			$val = find_editor($id, 'get', '');
    			if ($val == undefined) {
    				console.log('no wysiwyg visible, look for textarea');
    				$val = $('#' + $id).val();
    			}
    		}
    		console.log($key);
    		console.log($val);
    	});
    

    and then I added a function for get/set of the Tiny editor:

    
    function find_editor($id, action, value) {
    	$editor = false;
    	for (i=0; i<tinyMCE.editors.length; i++) {
    		console.log(tinyMCE.editors[i].id);
    		if ($id == tinyMCE.editors[i].id) {
    		// found the right one, set and stop
    		$editor = tinyMCE.editors[i];
    		break;
    		}
    	}
    	console.log($editor);
    	if (action == 'set') {
    		if ($editor) {
    			// this is a tinyMCE function call
    			$editor.setContent("some value");
    		}
    	}
    	
    	if (action == 'get') {
    		if ($editor) {
    			// this is a tinyMCE function call
    			return $editor.getContent();
    		}
    	}
    }
    
    

    So, this is beginning to work. I am not dealing with other inputs such as checkboxes yet.

  • Hello John,

    That is exactly what it is.

    Where and how the “Average” rating is updated on the Provider post I dont know. This is a plug-in I’m using.

    I know the answer on the When, when a new review gets submitted on the Provider post.

    With this function:

    function when_a_review_gets_submitted ($review, $post_id) {
    // Do something
    }
    
    add_action('rwp_after_saving_review', 'when_a_review_gets_submitted', 11, 2);

    I can do something after a new review is submited.

    I want to do this:

    // Set up the objects needed
    $hosting_provider_query = new WP_Query();
    global $post;
    $hosting_pagina_titel = $post->post_title;  
    $search_all_pages = $hosting_provider_query->query(array(
        'post_type' => 'page',
        'post_status' => 'publish',
        //Only get pages where custom field 'name_hosting_provider' equals Page title
        'meta_query' => array(
            'relation' => 'AND',
            array(
                'key' => 'naam_hosting_provivder',
                'value' => $hosting_pagina_titel,
                'compare'   => '='
            ),
    
        ),
    ));
    
    // Loop through all pages and find Page's children
    $loop_through_all_child_pages = get_page_children( get_the_ID(), $search_all_pages );
    
    // Loop through everything we got back
    if(!empty($loop_through_all_child_pages)){
        foreach($loop_through_all_child_pages as $child_page){
            // get the ID of each childpage
            $get_child_page_ID = $child_page->ID;
            // get the ID of each parent page of the child pages
            $get_parent_page_ID = get_queried_object_id();
            // Get the average score from post_meta of the parent page
            $get_average_score = get_post_meta( $get_parent_page_ID, 'rwp_user_score', true );
            // update each custom field of the childs with the average score data from the post meta of parent page
            update_field('gemiddelde_score_hosting_provider', $get_average_score, $get_child_page_ID);
        }
    }

    I once got it working when adding the above script inside the function with this extra action:

    add_action( 'template_redirect', 'when_a_review_gets_submitted' );

    but this is causing an error now and nothing is getting updated.

    Error

    Warning: Missing argument 2 for when_a_review_gets_submitted(), called in /var/www/vhosts/domainname.nl/httpdocs/wp-includes/class-wp-hook.php on line 286 and defined in /var/www/vhosts/domainname.nl/httpdocs/wp-content/themes/hosting-vergelijker/functions.php on line 452

    You have any idea how to get this done?

  • John,

    Thanks for the reply. I think a action/filter hook inside the loop might not be a bad idea. I tested the process out and it worked great.

    You can close this query.

    Cheers.

  • Hello, i found a solution, here is the code in the page:

    $video = get_field('video_youtube');
    if (!empty($video)){
    echo video_iframe_YT($video);
    echo '<iframe width="560" height="315" src="' . $video . '" frameborder="0" allowfullscreen></iframe>';
    }

    and the functiun :

    // VIDEO YT : iframe
    function video_iframe_YT($video_url)
    {
    $video_iframe			= '';
    // -----------------
    if( !empty($video_url))
    {
    $video_url = video_cleanURL_YT($video_url);
    $video_iframe = '<iframe width="560" height="315" src="' . $video_url . '"  frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>';
    }
    // -----------------
    return $video_iframe;
    };
    ?>

    I hope it will help someone!

Viewing 25 results - 9,526 through 9,550 (of 21,340 total)