• Hi to everyone,

    I have some questions regarding the best way to organise an online personal project of mine. I looked in several resources but could not really figure this one out.

    I am using WordPress combined with ACF (Advance Custom Fields) so the user can generate a table that has a fixed amount of columns but the number or rows is variable. I have like 10 of this, they are products’ characteristics that relate to a product page.

    In the front end the users can pick which of the previous products’ characteristics want to display, something similar to a comparator tool (e.g. http://youcompare.com.au/mobilephones/compare).

    My guesses are:

    1-I need to collect the user choice. Is it the best way to do so using JavaScript? All the extra functionality should be done via JavaScript (I guess jQuery is good too).

    2-I need to pass the JavaScript collected choice to the PHP function that prints the function out. Is the best way to do this using AJAX?

    3-I need a PHP (?) function that receives the user choice (via parameters I guess) and prints the function out.

    Are all these steps correct?

    About point 3 I have a couple of questions:
    A-Is PHP suitable for doing this?

    B- Where should I define the function? Can I create a separate file in WordPress (eg. print-table.php) for only this function?

    C-How do I then make my theme know that this function exists? (I know it is a basic stupid question but could not figure it out).

    D-Can I display the changes (e.g. adding a new product to the comparison or removing a product from the comparison) without having to reload the page?

    Thanks a lot for your time. I am sorry if this has been asked before but during my research I wasn’t able to figure all these out.

    I am using a local installation of WP 4.3 and 4.4.4 of ACF.

    Cheers,
    Josep

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi Josep, my personal view+ideas :-)..

    1) yes, cant be wrong
    2) yes, AJAX is the way to go
    3) yes, PHP is needed to get ACF data

    3A) yes
    3B) good starting point is “functions.php”, once all is running I personally would move it to an extra plugin. To be “theme-update save”.

    3C) I recommend to study this post here: http://wordpress.stackexchange.com/questions/158364/ajax-call-in-wordpress-front-end
    When WP is called in browser it also loads things like add_action(‘wp_ajax_nopriv_my_action’, ..) and hooked functions.

    3D) If you use AJAX for that, yes. No reload needed.

    Thread Starter jmgarciabonilla

    (@jmgarciabonilla)

    Hi Andreas,

    Sorry I reply this way too late, unacceptable from my side.

    Thanks a lot for your guidance and advice. This ha been revealing for me, I’ll take your advice and move it all to an extra plugin, sounds like a really organized idea.

    I’ve been actually catching up in my JS skills, particularly JSON, AJAX and WP REST API. All these is really exciting and I fell positive about building it up.

    As I said, thank and very sorry about the way-too-late reply.

    Cheers,
    Josep

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Where to add php code and how to pass data from JavaScript’ is closed to new replies.