Support

Account

Forum Replies Created

  • Solved. Using the variable $post_id returns the correct data for that block.

    $wf_settings_width = get_field('wf_settings_container_size', $post_id);'

  • Ok, I have just realised that I am trying to obtain block data, rather than post data that does not exist. Silly me.

    My next question is, how do I get the block data, when it isn’t returning any via get_template.

    I am building a set of global templates for the blocks which is why I am including them, rather than having the code directly in the template.

  • I’m guessing you already solved this, but for future reference, this is what I use and it works great. Depending on your own setup, you may want to add more conditional statements to trigger only on certain post types.

    function generate_video_thumbnail($post_id, $post) {
    	$current_post_thumbnail = get_post_thumbnail_id( $post_id );
        if ( '' !== $current_post_thumbnail ) {
            return;
        }
    	
    	$url = get_field('video_embed', $post_id, false);
    	$oembed = _wp_oembed_get_object();
    	$provider = $oembed->get_provider($url);
    	$oembed_data = $oembed->fetch( $provider, $url );
    	$thumbnail = $oembed_data->thumbnail_url;
    	$title = get_the_title($post_id);
    	
    	if($url) {
    		$image = media_sideload_image( $thumbnail, $post_id, $title, 'id' );
    		set_post_thumbnail( $post_id, $image );
    	}
    }
    add_action('save_post', 'generate_video_thumbnail', 12, 3);
  • I just use html entities when adding instructions, to prevent the tags from rendering.

  • No luck so far unfortunately. I emailed the REST to ACF plugin author (who replied very quickly!) and he confirmed there currently isn’t an action to indicate an item was saved. His only suggestion was a filter that runs prior to saving ACF.

    add_action('acf/rest_api/post/prepare_item', function($item, $request){
    	// do something	
    }, 10, 2);
    

    Not too sure if that would help anyone else – if someone finds a creative solution please let me know!

    For the time being, I’m thinking of just setting up a CRON job to email every x amount of minutes/hours.

  • Cool, so aside from the duplication, it seems to work fine as the goal is to redirect to the URL if a correct code is entered.

    Code so far:

    	<?php 
    	$codeErr = "";	
    	$code = ""; 
    	if ($_SERVER["REQUEST_METHOD"] == "POST") {
    		if (empty($_POST["code"])) {
    			$codeErr = "<strong>Error:</strong> Promo code is required";
    		} else {
    			$code = code_input($_POST["code"]);
    			if (!preg_match("/[A-Za-z0-9]+/",$code)) {
    			   $codeErr = "<strong>Error:</strong> Incorrect promo code. Please try again."; 
    			} else {				
    				$rows = $wpdb->get_results($wpdb->prepare( 
    					"
    					SELECT * 
    					FROM wp_vrtny1k0kz_postmeta
    					WHERE meta_key LIKE %s
    						AND meta_value = %s
    					",
    					'promosettings_%_code',
    					''.$code.''
    				));	
    				if (!$rows){
    					$codeErr = "<strong>Error:</strong> Incorrect promo code. Please try again."; 
    				}
    			}
    		}	
    	}	
    	function code_input($data) {
    	   $data = trim($data);
    	   $data = stripslashes($data);
    	   $data = htmlspecialchars($data);
    	   return $data;
    	}
    	?>
    	<div class="row">
    		<div class="col-sm-6 col-xs-12">
    			<form action="<?php echo get_permalink(); ?>" method="post" id="promo">
    				<div class="row">
    					<div class="col-sm-9 col-xs-8">
    						<input type="text" name="code">
    					</div>	
    					<div class="col-sm-3 col-xs-4">	
    						<input type="submit" name="submit" value="Submit"> 
    					</div>
    				</div>
    			</form>
    			<span class="error"><?php echo $codeErr; ?></span>
    		</div>	
    	</div>
    	<?php 				
    	if( $rows )	{
    		foreach( $rows as $row ) {
    				preg_match('_([0-9]+)_', $row->meta_key, $matches);
    				$url_key = 'promosettings_' . $matches[0] . '_url';
    				$url = get_post_meta( $row->post_id, $url_key, true );
    				?>
    				<script>
    					window.location.replace("<?php echo $url; ?>");
    				</script>
    				<?php
    		}
    	}

    Edit – added a counter. Not sure if this is the most effective way, but it works

    	if( $rows )	{
    		$i = 0;
    		foreach( $rows as $row ) {
    			if($i == 0) {
    				preg_match('_([0-9]+)_', $row->meta_key, $matches);
    				$url_key = 'promosettings_' . $matches[0] . '_url';
    				$title_key = 'promosettings_' . $matches[0] . '_title';
    				$url = get_post_meta( $row->post_id, $url_key, true );
    				$title = get_post_meta( $row->post_id, $title_key, true );
    				echo $url;
    				echo $title;
    		
    			}
    			$i++;	
    		}
    	} 
  • Ok, so changing

    preg_match('_([0-9]+)_', $row->meta_key, $matches);
    				$meta_key = 'promosettings_' . $matches[0] . '_url';
    				$url = get_post_meta( $row->post_id, $meta_key, true );
    				echo $url[0]; 

    to

    preg_match('_([0-9]+)_', $row->meta_key, $matches);
    				$meta_key = 'promosettings_' . $matches[0] . '_url';
    				$url = get_post_meta( $row->post_id, $meta_key, true );
    				echo $url; 

    Now shows me the URL, but duplicated.

  • The singular image field for a logged out user does not bring up the media gallery, but instead shows just a very basic upload a file from your computer box.

  • How would this be achieved in ACF 5?

  • Bumping as I’d like to know if there’s an answer for this.

Viewing 10 posts - 1 through 10 (of 10 total)