Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • Yes, i`ve declared this into a function in functions.php, this is my entire code:

    function asset_empty_indexes(){
    
      $post = get_post($_POST['post_id']);
    
      <?php // My post ID displays ?>
      <div class="hentry post" id="entry-<?php echo $post->ID; ?>">
    
        <?php // My post title displays ?>
        <?php echo apply_filters('the_title', $post->post_title) ?>
    
        <?php // My post content displays ?>
        <?php echo apply_filters('the_content', $post->post_content); ?>
    
         <?php // My basic field displays ?>
          <?php
           $value = get_field( "prueba", $post->ID );
           echo $value;
           ?>
    
        <?php // But my repeater field does not displays ?>
        <?php if( have_rows('attachment_field', $post->ID) ): ?>
          <ul>
            <?php while( have_rows('attachment_field', $post->ID) ): the_row();
               $valueField = get_sub_field('attachment_name' );
            ?>
            <li>
                <p><?php echo $valueField; ?> </p>
            </li>
           <?php endwhile; ?>
          </ul>
        <?php endif; ?>
    
      </div>
    
    }

    Iยดm, using it this way because i call this function with ajax to insert it in a wordpress post, all my fields show except repeater field.

  • @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.

  • @markbloomfield

    Thank you very much for your instruction. However, I have been through the step 1 to 5 but nothing happens. This is what I have done:

    1. I created a form group.
    2. I created a page to display this form.
    3. I put the 2 bits of code into the function.php in my child theme.
    4. I created a new page template. I do this by adding the given code from your instruction#5 into Notepad. Then I add this template page (.php) into my theme directory. After that I go back to the page I have created earlier (instruction#2). Under Page Attributes, I select the template page I’ve just created. Finally, update and view the result. I see nothing on that page. Also clear cache still nothing comes.

    Note: In the Location rule in ACF, I have also tried both rules below but it does’t work:
    1. Show this field group if PAGE equal to “the page I create for the form”
    2. Show this field group if Page Template equal to “the template page I create for the form.”

  • 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 ๐Ÿ™‚

  • 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 @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?

  • 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 ๐Ÿ™‚

  • As far as I know, the hooks available on the front end are the same as the hooks available in the admin and ACF uses the same code for displaying them both, except for the inclusion of form wrappers and other markup.

    Thanks, you’re right. I’ve assumed that these filters are admin panel specific, and I didn’t even check if my assumption is correct ๐Ÿ™‚

    There isnโ€™t any filters or actions that will let you add code between fields.

    It would be great if there were actions like acf/before_field, acf/after_field, acf/before_field_grup, acf/after_field_grup. So, can you convert this topic into a feature request?

    Thanks.

  • @markbloomfield

    Hi, thanks for your information. Glad to hear that’s possible.But it seems to be doable and easy for a person who knows how to do. But for me, I don’t know. I have been through the forum to read information and also checked the documents, still I don’t understand how to do, for example display a form in frontend. Many people just mention about the code, but I did’t know where to put the code, step by step, not mention clearly. So it’s very hard for me to do. If I buy the plugin wothout solving to my request, then I would end up with nothing because it’s very hard for me to use this plugin.

    Sorry I did’t indicate clearly about the form for login users. I mean I want only the author who creates a post can edit that post, other authors cannot.

    Thanks.

  • @beee – I posted my own question here – because my previous post was in a response to someone else’s question I wasn’t expecting to get an answer there, however it was followed up on. So this post became redundant.

    However i’m leaving it in place in case anyone has the same question and is looking for a solution.

  • Hiya @topy

    In short, yes everything you describe is doable.

    1) You can create an ACF form and then embed this form onto a page and tell the form that it needs to create a new page, post or custom post type. You can also wrap this code into a check to see if the user is logged in so that only logged in users can access this form.

    2) You can set the form to always create ‘draft’ posts by default. Or alternatively, you can make it a changeable field and combine it with a hook to actually make the post draft or published. I’ve actually recently done this myself. You would have a field in your ACF form called ‘status’. Then you create a hook that is triggered when this form is submitted. It would get the value of that field, and use it to set the status of the post.

    3) The same code that renders the form onto the page from item 1 above, can be used but with a different parameter that edits a post instead of creating a new one.

    For example, on your page where you have the form embedded, right at the top you’d have:

    
    /**
     *      Is something being edited?
     *      Is the user trying to do this, the author of the post being edited, or an admin?
     *      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_administator()) {
        $new_post = $_GET['edit'];
      } else {
        header('Location: '.get_bloginfo('home'));
        exit;
      }
    } else {
      $new_post = 'new_post';
    }
    

    So if your post create page is website.com/new-post then to edit a post using that same form, you’d have website.com/new-post?edit=23 and then you’d be editing post 23.

    And to actually embed the form that uses the logic above, you’d have:

    
    $formoptions = array(
      'post_title'      => true,
      'post_content'    => false,
      'post_id'         => $new_post,
      'field_groups'    => array(256),
      'submit_value'    => 'Publish',
      'return'          => get_permalink(142),
      'uploader'        => 'wp'
    );
    acf_form($formoptions);
    

    Hope this answers your questions and helps you confirm the purchase of ACF. It definitely is an incredible piece of software and worth absolutely every penny ๐Ÿ™‚

  • I tried now the following:

            acf_form(array(
            'form' => false,
            'field_groups' => array('videos'),
            'fields' => array('video_url'),
        )); ?>

    However, I get no repeater front-end field back, cause I just can edit 1 field. See below how my frontend looks like:

    Repeater Field

    Any suggestions?

  • Thanks John – I figured something out.

    I wrote this function:

    
    function generate_acf_shortcode( $field ) {
     echo '<pre>[post-snippet post="'; print_r($field['value']); echo '"]</pre>';
    }
    
    add_action( 'acf/render_field/type=page_link', 'generate_acf_shortcode', 10, 1 );
    

    This generated the proper snippet syntax (actual short code i wrote elsewhere) inline with my page_link fields.

    I followed that up by altering it to this:

    
    function generate_acf_shortcode( $field ) {
      $_SESSION['acf_post_link'] = $field['value'];
    }
    
    add_action( 'acf/render_field/type=page_link', 'generate_acf_shortcode', 10, 1 );
    

    and then in the EMF field I called this to pull those values in for each field:

    
    [post-snippet post="<?php echo $_SESSION['acf_post_link']; ?>"]
    

    Ended up With this:

  • I don’t think that wp-optimize will remove meta values and options, at least I don’t get this from reading the description and features, so I don’t think that it will hurt to use it. Maybe I’m missing something. It appears to delete orphaned data that could possibly be left behind when a post or some other object is deleted but not all of the meta values for that object are deleted. Honestly, I’ve never seen this happen except by going into the database and deleting posts from there rather than doing so through the admin.

    Deleting content when an ACF field is deleted is easy, relatively. Please note that the use of this function cannot be undone and it will erase all traces of content for any ACF field that is deleted. Also, I don’t use prepare in this, some people will probably find issue with that. It could probably be done with the first query, but I don’t think it can be done with the second query. Anyway, the object here is to wholesale delete all of the content with the least number of queries possible.

    Please, please be sure that this is something that you want to do before implementing this and I would strongly suggest that this is only enabled during development and not on a live site. Should a client go into ACF for some reason and delete a field, there is nothing that you’d be able to do to recover form it.

    
    <?php 
      
      // this action is run by ACF whenever a field is deleted
      // and is called for every field in a field group when a field group is deleted
      add_action('acf/delete_field', 'delete_acf_content_on_delete_field');
    
      function delete_acf_content_on_delete_field($field) {
        // runs when acf deletes a field
        // find all occurences of the field key in all tables and delete them
        // and the custom field associated with them
        global $wpdb;
        // remove any tables from this array that you don't want to check
        $tables = array('options', 'postmeta', 'termmeta', 'usermeta', 'commentmeta');
        foreach ($tables as $table) {
          $key_field = 'meta_key';
          $value_field = 'meta_value';
          if ($table == 'options') {
            $key_field = 'option_name';
            $value_field = 'option_value';
          }
          $table = $wpdb->{$table};
          // this query gets all key fields matching the acf key reference field
          $query = 'SELECT DISTINCT('.$key_field.')
                    FROM '.$table.'
                    WHERE '.$value_field.' = "'.$field['key'].'"';
          $results = $wpdb->get_col($query);
          if (!count($results)) {
            // no content found in this table
            continue;
          }
          // loop through keys and construct list of meta_key/option_names to delete
          $keys = array();
          foreach ($results as $key) {
            $keys[] = $key; // delete acf field key reference
            $keys[] = substr($key, 1); // delete acf field value
          }
          // do escping of all values.... just in case
          $keys = $wpdb->_escape($keys);
          // delete all of the content
          $query = 'DELETE FROM '.$table.'
                    WHERE '.$key_field.' IN ("'.implode('","', $keys).'")';
          $wpdb->query($query);
        } // end foreach table
      }
    
    ?>
    
  • Hi John,

    The issue is because there’s no way to pass a custom array of $args into the acf_get_posts() function from the acf_field_post_object::get_posts() method as there are no filters in this method and it’s being called by acf_field_post_object::render_field().

    That’s why the snippet in my original post suggests adding the three filters so this can be adjusted if we need to do so.

    The post status adjustment in acf/fields/post_object/query is to allow the AJAX search to search for that specific post status, otherwise again it uses any which will miss out my custom archived status. This section works perfectly, the issue comes when the field is then rendered on page load using acf_field_post_object::render_field() which comes back as blank.

  • I’m a little confused at why setting the post status using acf/fields/post_object/query. The first think ACF does in this function is call wp_parse_args($args, $defaults). Since post_status of any is a default value, is should not override the status that you set in your filter. If this is causing the post object field to get no results it seems like there should be something else causing it.

  • Fantastic. That was easy enough – thanks John, feeling my way through these hooks. One more question – I’ve been exploring the enhanced message field plugin you’d mentioned above, there’s not much by way of documentation on it and I’m thinking it’d be great to do similar to what i posted above – but instead of inlining the field output below or above the field, to display it in an enhanced message field next to the field. (eg. selector field | enhanced message field with selector field output)

    Is there away to write that for the EMF?

  • Indeed. So far, I have this thanks to their help…

    // 4. WPAllImport function - Import "avatar" user meta from first available image URL in input data
    
    function profile_photo($photo_url,$cb_avatar,$cb_twitter_avatar,$cb_aboutme_avatar,$cb_gravatar_avatar){
       if(!empty($photo_url))
           return $photo_url;
       if(!empty($cb_avatar))
           return $cb_avatar;
       if(!empty($cb_twitter_avatar))
           return $cb_twitter_avatar;
       if(!empty($cb_aboutme_avatar))
           return $cb_aboutme_avatar;
       if(!empty($cb_gravatar_avatar))
           return $cb_gravatar_avatar;
    }
    /* Execute in WPAI import using...
    [profile_photo({photo_url[1]}, {cb_avatar[1]}, {cb_twitter_avatar[1]}, {cb_aboutme_avatar[1]}, {cb_gravatar_avatar[1]})]
    ... wherein profile_photo is function name) */

    I will update this thread if I learn more.

    I had looked at the WPAI docs but, though I understand any PHP can be used in the functions and I have a smattering of PHP, I still needed some info to get going on basics like passing variables in and out of the function.

    Thanks.

  • In my list, I’ve basically listed different things in order of difficulty. For example, it is actually pretty easy to delete all of the existing data for a field if a field is deleted.

    When you start getting into the other things, quite honestly, I don’t really have the time to build an application that will root through all the fields in every group and try to find what matches up for something like changing the location of a field group.

    And when it comes to conditional logic, of altering sub fields of repeaters, or even renaming a field, if you want to accomplish this, even if you save other data to help in the process, it means that you need to inspect all of the data that was saved and compare it to all of the data that is saved and I think that this is something that is reasonable to achieve. The amount of work that would be needed to achieve it would far outweigh the benefit of it. To do this you would need to loop through every field group and every field, figure out what should be there and then delete anything that shouldn’t be there and the looping would need to actually look at the conditional logic associated with every field…

    … and then to complicate things even further. Let’s say that you have a tab field and this tab field is controlled with conditional logic. All the fields in the tab are conditional, but they do not need to have their own conditions since the tab controls it. Now, with every field you need to look and see… is this field in a tab? does the tab have conditional logic? should all fields in the tab be removed?

    Like @redvolver says, and I mentioned before, it could be done easily if you just flush everything when a post is saved and make ACF update with new values. The main issue with this method would be clone fields. The reason for this issue is that clone fields causes duplicated field keys. There are some other conditions that could also create duplicate field keys, for example, registering field groups using PHP and using the same field in several places without using a unique key.

    Like I said, I started building something that would do this automatic cleanup, but clone fields stopped me, since, in the end the only thing you really have to go by is the field key. Even a process that must be initiated by an admin would have these problems.

    I’ll continue to think about the issue and if I think of some way to accomplish it without writing a million lines of code to make it safe I will.

  • Thanks a million John managed to figure it out in the end I was missing the post id at the end of the short code call
    Cheers for coming back to me on this really didnt expect it after 2 years thanks again ๐Ÿ™‚
    Heres how the code looked in the end

    <img src="[acf field='list_of_sdgs_0_sdg_icon_image']" /> <a href="[acf field=">[acf field="list_of_sdgs_0_sdg_name"]</a>: [acf field="list_of_sdgs_0_sdg_purpose"]
    
  • Hi, I seem to be having a bit of a problem. I used Beee’s code and altered it to fit my taxonomies, but unfortunately it’s not working as wanted.

    I have a custom post type with a taxonomy (‘type’), type can either be ‘movie’ or ‘series’.

    My ACF Radio button field has these choices, the value given is the value of the term:

    2 : Movie
    4 : Series

    This will output the value of the field, not the name or array.

    In my functions.php I have:

    function change_media_type( $post_id ) {
        // bail if no ACF data
        if ( empty($_POST['acf']) ) {
            return;
        }
        // get term id from $post_id (only 1 value is allowed, so it returns 1 value only)
        $stored_type = wp_get_post_terms($post_id, 'type');
        // get submitted value from acf form
        $posted_type = $_POST['acf']['field_picktype'];
        // get term_id for the submitted value
        $term_id = get_term_by( 'id', $posted_type, 'type' );
        // if stored value is not equal to posted value, then update terms
        if ( $stored_type != $posted_type ) {
            wp_set_object_terms( $post_id, $term_id->term_id, 'type' );
        }
    }
    add_action('acf/save_post', 'change_media_type', 20);

    But it doesn’t seem to change the taxonomy of the post as I want. It changes, but simply changes to “โ€””. Could anyone point me in the right direction?

  • Hi John / ericaeide

    Chances are that this wont get answered as its been 2 years since the initial post but you never know ๐Ÿ™‚

    Im having issue calling a repeater field with the above code can you have a quick look at what im doing and let me know where I have gone wrong?

    —-SET Up—-

    Created New Field Group called test list and attached it to a page using the rules

    The first item is called list items (field name list_items) this is set to repeater

    The next field in the repeater is called item and its just plain text (field name item)
    The next field in the repeater is called item image its just plain image upload (field name item_image)

    The short code im using to call this onto another page is as follows

    [acf field="list_items_0_item"]

    It calls on the list page but i cant seem to pull that list into another page by using that shortcode do I need to reference the page id?

    Should this be returning all the items I have entered?

    Thanks in advance for your help if you get this ๐Ÿ™‚

  • Hi all,
    if you look at my try to achieve this:
    https://github.com/filippozanardo/redvolver-acfcleaner

    You see that ,expect some field that i didn’t found a way yet, can be made in 2 ways, one is as john say delete all the meta related to ACF on acf/save_post hook at high priority.
    The other a more difficcult way is to match the field in the database/json and then to delete the field that is not present anymore in the current saved data.
    I found a trick also to check if the field is a flexible field and delete the field.
    As far as i test works remember to backup db first.

    For now works on post and custom post type when i have time i want also to include a “Clean all ACF” tool that use this method, and i’m trying also to find a way to “clean” all the fields for taxonomy, user etc etc.

    Suggestions, ideas and pull requests are welcome.

  • First of all, thanks for even spending the time and effort with the issue, I’m sure I speak for all above.

    In reference to the latter part of your last post, and keeping in mind I’m not even remotely close to having the dev knowledge you have.. but maybe sometimes someone without the knowledge could introduce something so elementary that it may have gotten overlooked ๐Ÿ™‚

    You said, “What data do you think ACF could store to help make the clean up of data in each of the above conditions easier?

    Once again, coming from an elementary view.. If and when ACF creates a (_postmeta, _termmeta, _usermetaโ€™, _commentmeta and options) it would also log that creation. Maybe chain it (create a relationship) of this specific creation and attach a unique serial number to it. So when it is “clean up time”, that specific and unique action was taken can then be read by ACF, and then go back and erase / clean up no longer used data.

    How could ACF overcome the limits of WP when it comes to the issue of performing all of the checking and deletion of data from the five locations where it can be stored (_postmeta, _termmeta, _usermetaโ€™, _commentmeta and options) when each check/deletion will require calling a WP function to delete the specific data?

    Maybe not an ongoing cleaning process, but one initiated by admin when it’s an optimal time for that site. A tab / setting in admin to click “clean” button, accept warning and then clean. Obviously warning one to backup DB first.

  • Ahhhh my bad! I really should’ve researched a bit further before posting my question.

    It is indeed a browser thing so, for anyone interested in avoiding this situation when it’s unwanted, simply use this bit of JS on your dismiss/close JS call:

    // Remove navigation prompt
    window.onbeforeunload = null;

    Source: https://stackoverflow.com/questions/1119289/how-to-show-the-are-you-sure-you-want-to-navigate-away-from-this-page-when-ch

Viewing 25 results - 11,026 through 11,050 (of 21,318 total)