Support

Account

Forum Replies Created

  • Hello,

    I am having this issue again now with WP 4.3 and ACF pro 5.3.
    I can upload svg into wordpress editor and I can also preview them in the post editor but when I click on “save / publish” the image dissappears and after loading the post again the image field is empty. Any ideas?

  • Actually to the code that I found in the documentation for Oembed, I just added

    			$params = array(
    				'controls'    => 0,
    				'hd'        => 1,
    				'autohide'    => 1,
    				'autoplay' => 1
    				);

    and it worked perfectly. Maybe you modified this in the code? but this solution its very intuitive and it works good.

  • I managed to solve it and my error was a very basic one.

    I just had to call my field with an ID, such as:

    $title = get_field('title', $post->ID);
    $caption = get_field('caption', $post->ID);

    adding $post->ID in order to be able to reference the template part from anywhere, just because I was pulling this info from a post object.

    For those seeking the same, these have been enlightening links:
    http://www.advancedcustomfields.com/resources/how-to-get-values-from-a-media-attachment/
    http://www.advancedcustomfields.com/resources/how-to-get-values-from-another-page/

  • Ok, I might be wrong, but I don’t think the shortcode will let you retrieve values from a user. A shortcode only let you indicate field name and post_id.

    But this might point you out in the right direction:
    http://www.advancedcustomfields.com/resources/how-to-get-values-from-a-user/

    The documentation says:

    All the API functions can be used with a user, however, a second parameter is required to target the user ID. This is similar to passing through a post_id to target a specific post object.

    The $post_id needed is a string containing “user” + the user ID in this format: “user_$UserID”

    You will need to specifiy the user_ID for that. But as I said before, I dont think that’s available in a shortcode.

  • If I understand your answer correctly, if <?php get_sub_field($caption); ?> for flexible fields works only inside <?php if( get_row_layout() == 'full_width_image' ): ?> and that need to be inside the flexible field while loop, then there is no way to split this captions into smaller files, no?

    I can’t call the loop in the main file and call the loop again in the captions file, because it breaks everything.

  • My code has several levels. This code I sent you before is the code for projects-image.php (see get get_template_part below) and the loop for my posts is inside projects.php, from where I am calling different files with different ACF structure, like this:

    <?php get_header(); ?>
    
    <?php
    /*
    Template Name: Projects
    */
    ?>
    
    <?php $query = new WP_Query( 
    	array( 
    		'posts_per_page' => 1, 
    		'category_name' => 'projects',
    		'orderby' => 'date',
    		'order'      => 'DESC'
    		));
    
    if ( $query->have_posts() ) {
    	while ( $query->have_posts() ) {
    		$query->the_post();?>
    
    				<div class="row">
    					<article class="projects large-12 columns ">
    						<section class="large-6 large-centered columns">
    
    							<?php if( have_rows('projects_content') ):
    							while ( have_rows('projects_content') ) : the_row(); ?>
    
    							<?php get_template_part( 'project', 'image' ); ?>
    							<?php get_template_part( 'project', 'video' ); ?>
    							<?php get_template_part( 'project', 'text' ); ?>
    
    						<?php endwhile;?>
    					<?php endif; ?>
    				</section>
    			</article>
    		</div><!-- end.row -->
    
    	<?php // Copyright ?>
    	<div class="row">
    		<?php get_template_part('/parts/copyright'); ?>
    	</div>
    
    	<?php }
    } else {
    	// no posts found
    }
    // Restore original Post Data
    wp_reset_postdata();?>
    
    <?php get_footer(); ?>
  • @hpctech the answer is simple: In your case the ACF is empty, because there is no place so far where you are filling the information that this field should be displaying. The ACF is a “container”, but from where is this container grabbing the information that should be displayed?

    Let’s say you use a post to do this. If I am not wrong in your current settings, if you go to Posts > Add new, you will see the new sms2 field you created (below the content editor). Fill that text area with something, a number, whatever, and save it, then in the page where you are using the shortcode write [acf field="sms2"] or [acf field="sms2" post_id="524"] and replace 524 for the post-ID from where you want to grab this info.

  • hi @brian1037

    to show the number of views a post has >> that’s completely out of the scope of the ACF, it’s not even connected with the plugin. Probably there are actually other WordPress plugins that can do that.

    And you can make the fields visible only to administrators, check this one out:
    http://www.advancedcustomfields.com/resources/custom-location-rules/

    Cheers

  • Ok, now it’s clearer.

    My question would be: if you just need to output text in a WYSIWYG field, why dont you just write the text in the_content() and attach the audio to that field as well? Why two fields?

    But try this code and tell me if it works:

    <div class="chapo">
    	<?php the_field('chapo'); ?>
    </div>
    
    <div class="content">
    	<?php the_content(); ?>
    </div>

    If it doesn’t, can you inspect the html with chrome or firefox and tell me what’s being displayed inside these divs?

  • @mediawerk thanks for your answers.

    My code is indeed a flexible field and when I put the code which I am trying to put in a separate file, into my whole code, it works. It’s just that when I put it out of the context or I try to call it from a function, it doesnt work anymore.

    I don’t know if it makes so much sense to put my entire code, but here it is:
    http://pastebin.com/vC6b4fXw

    I want to put in a separate file everything that is inside the <figcaption>tag (or create a function that will load that code). My problem so far is, that if I put this code in a template file and I call it with a normal <?php get_template_part(); ?> or with a function via functions.php for example, my caption appears empty. While if I leave it inside my main loop, the captions are there.

  • can you specify:

    1) what are you puting in the chapo field.
    2) what are you putting in the content editor
    3) where / how is the attachment being added
    4) whats the code in your php file
    5) what should be the desired output?

  • OK, it’s an error in the php logic. In your code you are saying IF chapo, display ‘chapo’ and also the_content(). You need to use ELSE to display one or another, such as:

    <?php $field = get_field('chapo');?>
    <?php if( !empty($field) ) { ?>
    <?php echo $field; ?>
    <?php } else { ?>
    <?php the_content(); ?>
    <?php } ?>

    I am also adding a condition that says: if ‘chapo’ is not empty. Which is helpful most of the time.

    Cheers!

  • unfortunately, putting the code in a separate php file doesnt work, my captions are empty.

  • thanks for the hint. how would I use the $post_id, exactly?

  • Actually the code you need is already in the documentation, it’s very much detailed and almost all user cases are explained there.

    For example here

    Follow these steps and be sure you are calling the fields from inside the loop!
    http://codex.wordpress.org/The_Loop

  • Can you explain the steps that you are following?

    1) You are creating the page
    2) Editing the page using the “Text” editor (not the visual)
    3) Copying / Pasting the shortcode

    and its not working? Why is not working? What is exactly displaying?

  • I am not sure if someone will understand the problem. Can you explain it differently? I dont see how that screenshot is connected with the problem you are trying to describe. What’s exactly the issue?

  • Actually, I managed to solve this problem in another way. I post here the solution in case somebody else is interested in the answer:

    1) I created a Wysiwyg Editor field.
    2) Added the field normally in my php file.
    3) In the post editor, I used the normal wordpress “more” tag, which automatically inserts the shortcode <!–more–> inside my content and creates two paragraphs automatically, one before and one after the shortcode.
    4) In my Jquery file, I wrote this code:

           $('p').html(function(_, text) {
            return text.replace('<!--more-->', '<a href="#" class="read_more">read more</a>' );
          });

    That’s it, basically. With that link and that class I can manipulate the link as I want.

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