Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1217445
    Alejandro Jose S
    Participant

    Hi guys, i was wondering if there was a way to temporarily override a value using ACF API.

    You see, i want to remove the page i’m currently in from a grid containing it and other elements as items. I have created a Custom true/false field using ACF (called is_value) and have actually achieved what i want by creating 2 functions.

    the first one would update the is_active value with “false (0)” and thanks to the grid configuration it would not include it on the “visible” list. that function would be set in wp_head.

    The second one would update is_active with “true (1)”, allowing the page i’m at the moment to show later on.

    Here’s what the functions look like (don’t mind the “switch” i’m just testing a few things and i need it there for now):

    function post_types_grid() {
    	
    	switch ( get_post_type() ) {
    		case luoghi:
    		/* Removes Current item from Grid */
    			update_field('is_active', 0, false);
    			break;
    		case comuni_territorio:
    			echo 'Destinazioni';
    			break;		
    	}
    }
    add_action('wp_head', 'post_types_grid',99);
    
    function reset_default_grid(){
    	
    	switch ( get_post_type() ) {
    		case luoghi:
    		/* Resets default value */
    			update_field('is_active', 1, false);
    			break;			
    	}
    }
    add_action('wp_footer', 'reset_default_grid',99);

    i’m a bit new to ACF and i did read the documentation they have before asking here but frankly, it’s just too difficult to find anything in there (at least for me 🙁 ).

    I also tried googling my problem it but i’m starting to believe that i’m not phrasing the problem correctly because i’m not finding any useful information in there. i’m hoping you can point me to the right direction (maybe by telling me if there’s a function in ACF or The gird that does that, or even by pointing me to the right document).

    Thanks in advance!

    #1217760
    Rue Nel
    Moderator

    Hello There,

    Thanks for writing in! Would you mind providing us the url of your site with login credentials so we can take a closer look? This is to ensure that we can provide you with a tailored answer to your situation. Once you have provided us with your URL, we will be happy to assist you with everything.

    To do this, you can make a post with the following info:
    – Link to your site

    – WordPress Admin username / password

    Don’t forget to select Set as private reply. This ensures your information is only visible to our staff.

    Thank you.

    #1219107
    Alejandro Jose S
    Participant
    This reply has been marked as private.
    #1219853
    Nico
    Moderator

    Hi There,

    Would you mind sharing us also your FTP credentails so we could fully check your setup.

    Don’t forge to set it as private reply.

    Thanks.

    #1222312
    Alejandro Jose S
    Participant
    This reply has been marked as private.
    #1222730
    Nico
    Moderator

    Hi There,

    There is an update to the ACF Pro which is Supported Version: 5.4.8.

    Would you mind updating your ACF to the supported version.

    Let us know how it goes.

    Thanks.

    #1223570
    Alejandro Jose S
    Participant

    I just did that but the code is the same, hehe (i don’t think the outcome will change).

    As i said before, the code is working, but i was wondering if there was a BETTER way to do what i’m doing, i mean i doubt that there isn’t a way to temporary update a value and then just let it return as it was before, i just don’t know it. i’m new to ACF and even though i read the documentation (wich is not as well explained as yours) i didn’t find a function or a method to do something like that. 🙁

    #1223652
    Rad
    Moderator

    Hi there,

    I checked the discussion and your code and it seems not complete. I can’t understand what is the main purpose of removing and re-adding them on the same page. Is it a global grid? If yes, where it’s placed and how it should behave. Are there any other grids that will be called after removing it?

    And since you’re updating is_active, then there should be a place where you’re getting it. Where it is?

    Thanks!

    #1232849
    Alejandro Jose S
    Participant

    Hi rad,

    see here’s the main goal:
    i have a list of, say, 15 places. i want the grid to show all the places of that list BUT the active one.

    so what i’m doing now is to first create a function IN THE HEADER, where i remove the current page i’m on from the list. then the grid loads and then after it’s finished loading i add another function (on the footer) that actually adds the initial setting to the page.

    I do this because if i only add the header function it will actually removes the current place in its entirety from the grid so if i then go to another place of the list it will not show the first one (and if i visit every page, then, eventually i will have nothing showing on the grid).

    i was asking if there was a better function exactly because it’s a little orthodox to have to remove and then re-add the options on real time, but reading the documentation i found no way to temporary alter the value of the custom field.

    right now, the code actually works, i only thought of asking you to see if you knew of a better (more optimal) way to achieve the same thing, since you’ve helped me so much over these years and have even helped me IMPROVE my coding skills!

    #1233005
    Rad
    Moderator

    Hi there,

    Hmm, I’m not sure if I fully understand it. How does the page decide which is the active? I know it’s set as is_active, but on what condition.

    Though if it’s working, then it should be okay. I can’t think of any filter for ACF or even for the custom field, it always loop.

    Thanks!

  • <script> jQuery(function($){ $("#no-reply-1217445 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>