Support

Account

Forum Replies Created

  • @exove you could put this in your header:

    
    if (get_field('location')) :
      wp_enqueue_script('...');
    endif;
    

    …where location is the name of your field

  • Something like:

    
    <div class="show-on-desktop hide">
      Visible on Desktop
    </div>
    
    <div class="show-on-mobile hide">
      Visible on Mobile
    </div>
    

    and then your JS would be:

    
    var windowWidth = $(window).width();
    var $desktopVisible = $('.show-on-desktop');
    var $mobileVisible = $('.show-on-mobile');
    
    if (windowWidth <= 640) {
      $desktopVisible.addClass('hide');
      $mobileVisible.removeClass('hide');
    } else {
      $desktopVisible.removeClass('hide');
      $mobileVisible.addClass('hide');
    }
    

    CSS:

    
    .hide {display:none;}
    

    Like so?

  • Where you have $post = get_post($_POST['post_id']);, add this right below: setup_postdata( $post );

    Try that & lemme know?

  • @miguelaichon – that’s a key bit of information because that means that it’s not finding ‘attachment_field’ correctly.

    So you’d need to check some elementary things: Are you testing this on a post that in fact has content in that sub field? Is it named correctly?

    Also, if you are having to specify the post ID in all your other fields, perhaps you need to use it in the sub field too?… IE $valueField = get_sub_field('attachment_name', $post->ID);

  • Thanks @topy

    You had missed out step 6 from my tutorial completely – IE the code to actually show the form, was not placed into your Form.php page template.

    I did this, and the form showed immediately 🙂

    Screenshot of how the code should look: http://d.pr/i/QF9CP9
    Screenshot of your site with the form: http://d.pr/i/ZBtAym

    So all you need to do is open your Form.php and put this code wherever you want the form to appear:

    
    <?php
    	$formoptions = array(
    		'post_title'      => true,
    		'post_content'    => true,
    		'post_id'         => $new_post,
    		'new_post'        => array(
    			'post_type'       => 'post', // change this to the post type you need
    			'post_status'     => 'publish' // do you want the post to be published immediately? otherwise change this to 'draft'
    		),
    		'field_groups'    => array(9), // change this number to the ID of your field group
    		'submit_value'    => 'Publish',
    		'return'          => get_permalink(24), // change this ID to the page you want to send the user back to when they've submitted the form - perhaps a thank you page
    		'uploader'        => 'wp'
    	);
    	acf_form($formoptions);
    ?>
    

    Hope this helps 🙂

  • What do you see if you do print_r(have_rows('attachment_field', $post->ID)) ?

  • So

    1) you need to fetch the name of the brand, ie ford or bmw and you currently do this with $brand = get_field('brand');

    2) you then need to fetch the models using this brand variable and your naming structure is model_$brand essentially. to do this you’d then say $models = get_field('model_'.$brand);

    Have you tried this?

    What do you see if you try do print_r($models) ?

  • @topy the tutorial I gave you, is what I did on a site of my own in the last 2 weeks, so it definitely works.

    But i’d like to help check your code + setup on my end. If you don’t have a server to upload this to yet, then you can:

    1) zip up the whole WP folder for the site and upload it somewhere and give me the link here

    2) if you’re using WAMP, you should be able to browse to http://localhost/phpmyadmin to gain access to your databases so you can export them. Export the SQL file for your site and zip this up too and reply here with a link to both files. If you can’t get this right, then you can also find + install a plugin that will create a backup of your database and let you download it.

    Will wait for your reply here with those files 🙂

  • and is $post->ID echo’ing out the post ID correctly elsewhere? IE in the id="entry-<?php echo $post->ID; ?>" part?

  • @rameden learnt about it today too 🙂

    If this solves your problem, you can click on the ‘solved’ button for that answer, that’d be great 🙂

    Good luck!

  • @topy the site would need to be online somewhere for me to check. Do you have a staging/test server you can upload the site to? That would make it a lot easier to check 🙂

    Worst case scenario, is you can send me a backup of your entire site, and a backup of the .sql file and I can set it up on my localhost and check what’s happening…

    Whichever is easier for you.

  • @topy are you able to give me a URL and logins to this site perhaps so I can help?

  • Understand @rameden

    To answer your question directly, get_post_meta does just that: it fetches *post* meta.

    The equivalent of this function for WordPress *options* data, is wp_load_alloptions which you can read more about here.

    Hope this helps 🙂

  • Hi @rameden

    Is there a reason you’re not using the ACF functions for this?

    get_field('field_name') to get a post/page specific meta field, or get_field('field_name', 'option') to get a site options meta field.

  • HI @miguelaichon

    Your functions.php wont know what the value of $post is by default, so ideally you’d want to put that code into a function which passes the post ID value into it so that you can use that value.

    But why not just put this code directly into your template – single or page – and then you can be inside the loop where the post ID value will be known?

  • Hello @cuartostudio

    Ideally, you should use srcset for this (explained here). But if this isn’t an option, you can also use a bit of Javascript for this:

    Your HTML could look something like this:

    <img src="<?php echo get_field('image'); ?>" data-small-src="<?php echo get_field('image_small'); ?>" />

    Then the Javascript (jQuery):

    
    var windowWidth = $(window).width();
    
    if (windowWidth <= 768) {
      $('img[data-small-src]').each(function() {
        var small_src = $(this).data('small-src');
        $(this).attr('src', small_src);
      });
    }
    

    What that basically says, is if the window width is less than 768 (or whatever width you want this to happen), then find all the <img> tags with the data-small-src data attribute, loop through them and update its src value, with the ‘small-src’ value which will be the URL of the smaller image.

    You could optionally put that function into a $(window).resize event too so that it swaps out the images based on image size, but then you’ll need to add an else to that if statement so that it reverts back to the large size if necessary.

    Hope that helps?

  • Hi @topy

    Ok, so the steps would be as follows:

    1) create the form group with all the fields you want to be on your post
    2) create a page in wordpress where this form will ‘live’
    3) open your functions.php and add these 2 bits of code:

    
      /*----------  User Info  ----------*/
      // this creates a global 'USERID' which you can use to return the ID of the current user anywhere in your site
      if (is_user_logged_in()) {
        $current_user = wp_get_current_user();
        define('USERID', $current_user->ID);
      }
    
      /*----------  Check if I am an admin  ----------*/
      function is_administrator() {
        $current_user = wp_get_current_user();
        $roles = $current_user->roles;
    
        return (in_array('administrator', $roles)) ? true : false;
      }
    

    4) create a new page template to apply to this page (assuming you know how to do this?)
    5) in that template, put this at the very top of your file:

    
    <?php
    
      /**
       *      Is something being edited?
       *      Is the user trying to do this, the author of the post being edited?
       *      If not, redirect back to home
       */
      if (isset($_GET['edit'])) {
        // get the post being edited
        $thispost = get_post($_GET['edit']);
        if (USERID == $thispost->post_author || is_administrator()) {
          $new_post = $_GET['edit'];
        } else {
          header('Location: '.get_bloginfo('home'));
          exit;
        }
      } else {
        $new_post = 'new_post';
      }
    
      /* Template Name: My Post Create Page */
    
      acf_form_head();
      get_header();
    ?>
    

    You will use this page for both post creation, and post editing. To edit the post, just add ?edit=23 to the URL and that will let you edit post 23. Note that the above function will only let the author of post 23, or the administrator edit this post. Anyone else will be redirected to the home page

    6) Where you want the edit form to appear, put this code:

    
    <?php
      $formoptions = array(
        'post_title'      => true,
        'post_content'    => false,
        'post_id'         => $new_post,
        'new_post'        => array(
          'post_type'       => 'insights', // change this to the post type you need
          'post_status'     => 'publish' // do you want the post to be published immediately? otherwise change this to 'draft'
        ),
        'field_groups'    => array(999999), // change this number to the ID of your field group
        'submit_value'    => 'Publish',
        'return'          => get_permalink(142), // change this ID to the page you want to send the user back to when they've submitted the form - perhaps a thank you page
        'uploader'        => 'wp'
      );
      acf_form($formoptions);
    ?>
    

    —————–

    That should do the trick. Give it a go and let me know if you get stuck.

    Good luck!

  • Hey @alexstanhope – I checked this out now and that URL appears to be properly alphabetical as you say you wanted it.

    Safe to assume you fixed this problem?

  • @zeckart AFAIK not directly from Google Maps, but you can extrapolate this data from Google Places.

    Basically you do a Google Places lookup on the name of the place to get the “Place ID”. Then you use this ID to do a full lookup on Google Places which includes the Postal Code, amongst a plethora of other data.

  • Hi @cezilia_mar

    Not sure if I’m understanding your query, however the 1 problem I can see in your code is this: get_field('$modelos_marca')

    If you’re fetching a variable, you can drop the quotes so that it becomes: get_field($modelos_marca)

    So your code might be:

    
    $brand = get_field('brand');
    $modelo_brand = "modelo_" . $brand;
    
    if(get_field('marca')) {
      echo get_field($modelo_brand);
    }
    

    Alternatively, perhaps you could clarify your problem?

  • Hiya @jeffer

    Posts always need to be assigned to an author. So what I’d suggest is create a user in your admin to whom these posts will be assigned – Anon User – or whatever you’d like to call them. Remember to make sure they’re of the correct role to publish posts.

    Then in your acf_form function, specify this user to be the author of that post. In the args for your form, just add 'post_author' => 123 – where 123 is the ID of the user you’ve created.

  • Well when that time comes @topy, create a post here, CC me into the post and I’ll help you through.

    That snippet of code I gave in my last post does exactly that – it checks if the current user who’s trying to edit the post, was the author of the post. If so, it’ll let them edit. If not, it’ll redirect to the home page.

    In terms of displaying the form on any page:

    
    $formoptions = array(
      'post_title'      => true, // show the post title?
      'post_content'    => false, // show a body content editor?
      'post_id'         => $new_post, // this post should be new? or editing?
      'field_groups'    => array(256), // ID of the field group i want to show here
      'submit_value'    => 'Publish', // submit button text
      'return'          => get_permalink(142), // redirect URL
      'uploader'        => 'wp' // what type of uploader to use
    );
    acf_form($formoptions);
    

    It’s really quite simply and it’s all documented here.

    But more than that, these forums are here to help. So once you have your code almost there, come back and we can help you through the rest 🙂

Viewing 25 posts - 1 through 25 (of 53 total)