Support

Account

Forum Replies Created

  • No I’m sorry. I have no clue what you mean now.

  • I don’t understand where you ‘show’ the offers and how the users should ‘archive’ them. Is offer(s) a custom post type ?

    For my explanation I assume it is (because to me that would be the most logical solution). If it is, I wouldn’t use an ACF form for this because this sounds like a simple user meta storage to me.

    What you want (afaik) is exclude certain (post ids) from showing to the user.
    The ‘goal’ is then to store which ids need to be excluded for each user.

    You would need to create a page which has a form where a user can select which orders/posts have to be excluded.

    The code below needs to ‘go’ into the page which has the form (where users can exclude it).

    if ( isset( $_POST[ 'order_form_nonce' ] ) ) {
    
        if ( ! wp_verify_nonce( $_POST[ "archive_order_nonce" ], 'archive-order-nonce' ) ) {
            // not verified, so return and do nothing
            return;
        } else {
            $offers = ( isset( $_POST[ 'offers' ] ) ) ? $_POST[ 'offers' ] : false;
            if ( is_array( $offers ) && count( $offers ) > 0 ) {
                foreach( $offers as $offer_id ) {
                    $offers_to_archive[] = $offer_id;
                }
                update_user_meta( get_current_user_id(), 'offers_to_archive', $offers_to_archive );
            }
        }
    }
    
    $offer_args = array(
        'post_type'      => 'offer',
        'posts_per_page' => -1,
    );
    $get_offers = get_posts( $offer_args );
    
    if ( $get_offers ) {
        ?>
        <form name="archive_orders" action="" method="post">
            <input type="hidden" name="archive_order_nonce" value="<?php echo wp_create_nonce( 'archive-order-nonce' ); ?>">
            <?php foreach( $get_offers as $offer ) { ?>
                <input name="offers[]" id="offers" type="checkbox" value="<?php echo $offer->ID; ?>" /> <?php echo $offer->post_title; ?>
            <?php } ?>
            <input type="submit" class="button" value="<?php esc_html_e( 'Save', 'text-domain' ); ?>" />
        </form>
        <?php
    }

    Then you can use a simple exclude query to exclude the post ids which are stored by the user.

    $hide_offers_user = get_user_meta( get_current_user_id(), 'offers_to_archive', 1 );

    And then extend your query with this:

    'post__not_in' => $hide_offers

    Hope that helps…

  • Maybe I don’t quite understand… but the content you want to show is inside an ACF field on the thank you page ?

    If that’s the case you could just echo it with get_field( 'field_name' ).

  • You are right, I stand corrected.

    Have you tested with a higher or lower priority ?

    Higher
    add_filter('acf/settings/load_json', 'bks_acf_json_load_point', 1);

    Lower
    add_filter('acf/settings/load_json', 'bks_acf_json_load_point', 20);

  • Well, according to the local json info page, it needs to be unset, so that was step 1.

    What if you dump $paths in the save function ? What does it output ?

  • I don’t see the ID of the post you’re trying to edit to be passed into the form, but your code is not that easy to read 🙂 If you can still edit the post, please wrap it in back ticks (see the code button in the editor).

    Have you added acf_form_head() to your edit page as well ?

  • A 500 error does not mean it’s a memory issue, see this explanation. It means: “A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.”

    If it’s a memory issue, the error will say so.

    If the dropdown doesn’t work anymore, that sounds like a javascript error. Have you checked the console logs in your browser window and any error logs ?

  • Can you be a bit more specific please ?

    Don’t show the field where ? In the admin or in the output ?

  • Glenn,

    Can you please be a bit more specific ? What is generating the redirect to the thank you page ? Is it a plugin, is it your own code ?

    Depending on how the redirect is defined, you could pass the post id to the thank you page, so the url should be something like http://www.site.com/thank-you/?thnq={post_id-to-retrieve}

    Then on the thank you page, you need to add some code like this:

    if ( isset( $_GET[ 'thnq' ] ) ) {
        $content_to_retrieve = get_post( $_GET[ 'thnq' ] )->post_content;
        if ( false != $content_to_retrieve ) {
            echo $content_to_retrieve;
        }
    }
  • You need to add the following line to the load function because only 1 path may exists per load/save.

    unset($paths[0]);

    That being said, I think you should look into the issue why it’s not loading from the other site, because this is the default behaviour and should work, so something is blocking it.

  • I only use it to ‘upvote’ FAQ posts, not downvote, so only the upvote part is here but I think you get the idea and can create the downvote, based of this. Plus the output is written in twig instead of php but that’s not an issue I think.

    Code in template (code is as is)

    <div class="faq__helpful">
        <h4>{{ __( 'Was this helpful', 'textdomain' ) }} ?</h4>
        <div>
            <form class="faq_helpful" action="" method="post">
                <input type="hidden" name="post_id" value="{{ post.ID }}" />
                <input type="hidden" name="sd_faq__nonce" value="{{ function( 'wp_create_nonce', 'sd-faq-nonce' ) }}" />
                <button type="submit" name="helpful_yes" value="1" class="button item__delete-submit">
                    {{ __( 'YES', 'textdomain' ) }}
                </button>
                {% if helpful_yes %}
                    &nbsp;&nbsp;
                    <small>{{ _n( '%s person found this helpful', '%s people found this helpful', helpful_yes, 'textdomain')|format(helpful_yes) }}</small>
                {% endif %}
            </form>
        </div>
    </div>
    if ( isset( $_POST[ "sd_faq__nonce" ] ) ) {
        if ( wp_verify_nonce( $_POST[ "sd_faq__nonce" ], 'sd-faq-nonce' ) ) {
    
            // add helpful counter
            if ( isset( $_POST[ "helpful_yes" ] ) && '1' == $_POST[ "helpful_yes" ] ) {
                $faq_id = get_the_ID();
                if ( $hf_yes == false ) {
                    update_post_meta( $faq_id, 'sd_helpful_yes', '1' );
                } else {
                    $hf_yes = $hf_yes + 1;
                    update_post_meta( $faq_id, 'sd_helpful_yes', $hf_yes );
                }
            }
        }
    }

    Since this is not an ACF issue/topic I don’t wanna get too deep into this. WordPress.stackexchange.com is a better place for all WP questions.

  • What do you mean with ‘separated’ ?

  • I don’t think you need ACF for this I built something similar to show if a post was helpful or not. Basically you add post meta to a post, by adding or removing instances of 1.

    If someone likes the post he clicks the button and the counter will go up by one. If someone doesn’t like it the reverse will happen.

    This is stored in post meta so no need for ACF. And you can easily use this meta to sort the posts with.

    You need 1 form with 2 options.
    option + = update post meta with +1
    option – = update post meta with -1

  • A little addition, although it’s an older topic.

    I needed this as well, but as @andreasdm mentioned already, it needs to added ‘around’ each option that you retrieve.

    So I made it a bit easier, so you don’t have to add this around each get option field you use. I made a custom function (which needs to be added in functions.php) which returns the original value, based on the field name that is inputted.

    /**
     * Force return default language option value
     *
     * @param bool $field_name
     *
     * @return bool|mixed|null
     */
    function beee_get_filtered_option( $field_name = false ) {
    
        if ( false == $field_name ) {
            return $field_name;
        }
    
        /**
         * Set language to default
         *
         * @return bool|mixed
         */
        function beee_set_default_lang() {
            global $sitepress;
            return $sitepress->get_default_language();
        }
        add_filter( 'acf/settings/current_language', 'beee_set_default_lang' );
    
        // retrieve $field_name option value
        $value = get_field( $field_name, 'option' );
    
        /**
         * Reset to 'real' language
         *
         * @return mixed
         */
        function beee_reset_to_real_lang() {
            return ICL_LANGUAGE_CODE;
        }
        add_filter( 'acf/settings/current_language', 'beee_reset_to_real_lang' );
    
        return $value;
    }
    if ( class_exists( 'acf' ) ) {
        add_action( 'init', 'sd_get_filtered_option' );
    }

    Add this as is. No changes needed.

    Then call each option value like this:
    beee_get_filtered_option( $option_field_name );

  • I would still recommend looking into the acf/load_value filter.

  • You’re welcome… Can you also mark it solved ?

  • I agree with Nathan…

    I would use it differently. I would do something like this I think.

    $term = get_queried_object();
    $var = get_field('field_name', $term);

    Then loop through $var.

    if ( count( $var ) > 0 ) ) {
        $manager_name = get_sub_field('service_manager_name');
        if ( $manager_name ) :
          // do stuff
        endif;
    }

    Note this is from the top of my head, so untested.

  • Interesting question… but I don’t have an answer for you unfortunately (reg the radio button solution). I think it’s hard to prevent this, the way you set it up.

    What you could do (but this requires some coding) is to create 2 checkboxes instead of radio buttons for gender. Make this field required and don’t select a default value.

    Then with javascript, create a function that disables the other checkbox (on change), so only 1 option can be selected.

  • I have just done this, BUT I have done it in Twig, not in PHP, so you need to rewrite the twig back to php, which should be easy.

    <a href=""><img srcset="' ~ image_320 ~ ' 150w, ' ~ image_640 ~ ' 80w" sizes="(max-width:640px) 150px" src="' ~ image_640 ~ '" /></a>

    ‘ ~ is the same as ‘ . in php.

    image_320 and and image_640 are variables which contain nothing more than the file name.

    If the screen is bigger than 640 px wide, it uses the image_640 and otherwise the image_320.

    Hope this helps a bit.

  • I think you might be helped by reading this topic.

    I think I just explained something like this in the aforementioned topic.

  • This is a WP issue in my opinion, not an ACF issue, so I would recommend turning to the WP community forums for this.

  • I am not sure where this value is shown. Is this on the user edit page ?

    If I understand correctly, I think you need to look into creating a filter with acf/load_value, which sets the value upon load.

  • Gotcha, that last sentence is the key.

  • If I understand correctly your field has 2 options
    1) red
    2) blue

    If you update the field with the value checked, to which value should it apply ?
    You haven’t provided a real value which should be stored, only a string which does not occur in your options.

    And… checked is only used by checkboxes (afaik).
    In this case you would have to actually set the value of what you want to save.

    So you would have to save red or blue (assuming those are both the id and value).

    So I think you would have to do something along the line of:

    update_field('field_1234567890', 'red' );
    update_field('field_1234567890', 'blue' );
Viewing 25 posts - 126 through 150 (of 291 total)