• Resolved anonymized-14293447

    (@anonymized-14293447)


    I have a theme that, on creating listing from the frontend, stores data in the database both as customfields and arrays. I mean, all data are actual customfields but when I go edit a listing in the backend I can only find metaboxes of those that were not stored as array. So I need to create also metaboxes for all customfields that were stored as array.

    It’s a very difficult task for one who is not a developer, and there are no plugisn to do that (no ACF, no Metabox, etc.)

    So I was wondering if there is a set of PHP instructions I could add to my code, in order to view any listing in backend with ALL its data. Is there any?

    Thankyou

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    There is, but they would need to be developed ??

    What you could easily do is make a custom page template whose sole purpose is to execute any test code you might wish to try. You can enter code to list any particular array and even set specific values. Far from user friendly, but it would help you learn a little coding while you’re at it.

    Aside from the comment header required in the above link, below is a page code example. Given a particular post ID and field name, it’ll display field content, array or not. Add a WP page based on this template, then view the page. Edit as desired to achieve what you need. Unless you make it a private page, remember that anyone can view this page (if they know the permalink), executing any code on it. You could add code to only execute the main part if the logged in user is you.

    get_header(); ?>
        <div class="test_container" style="margin-left: 5em;">
        <!-- ----------------- Enter Test Script Below ------------------------------ -->
        <pre><?php
    
           $post_id    =  1234;      // Actual post ID goes here
           $field_name = 'foobar';   // Actual field name goes here
    
           $value = get_post_meta( $post_id, $field_name, true );
           print_r( $value );
    
        ?></pre>
        </div><!-- /test_container -------------------------------------------------- -->
    <?php get_footer();

    You could enhance this crude code in all sorts of ways. For example, add a WP_Query object to get a bunch of posts and display the same field of each post returned. If you keep adding little enhancements, a little bit at a time, you could eventually end up with a decent user interface. In other words, you could develop something. Hey, you’re a developer! ??

    Thread Starter anonymized-14293447

    (@anonymized-14293447)

    Thank you for the encouragement but it’s really beyond my current skills. You are suggesting to create a page that would output dynamic content, if I’m getting it right?
    But my goal is much simpler, I just want the array’s customfields to show in the backend as well as the other customfields do. The problem is also that the system generates 2 arrays (files) where data are clearly stored but interact with different functions.
    I’m probably not explaining well but that’s because I don’t know PHP.
    I thought it was just a matter of adding a few lines: pull data from arrays > create metabox in corresponding listing. Sounds like it doesn0t work like that ??

    Thread Starter anonymized-14293447

    (@anonymized-14293447)

    Before talking about development, if you bare with me a second you could make me understand how my theme works.
    As I exported my listings to a Excel file, the result is a table where data have each its own cell except one cell which contains the whole array.
    So I reckon another approach instead of using metaboxes would be that I could edit my data using Excel… but the array cell is one big chunk of data. I would then need the array converted into a separate Excel table, right? But how would I import and merge it into the corresponding listing?

    Sorry, I just realise that maybe this is too difficult for asking in the forum. I apologize for that. I won’t get offended if this thread becomes overlooked. ??

    Moderator bcworkz

    (@bcworkz)

    I understand what you would like, but AFAIK that would need to be custom developed. The plugins I’m familiar with don’t handle arrays. I was suggesting a path towards a solution that might be accessible to some novice coders. Of course it does not do anything close to what you want as is, but by adding functionality a little at a time, you could eventually get to some kind of useful functionality, even if it’s not the array editing meta box you really want.

    One could incrementally develop a meta box as well, but implementing meta box logic is more complicated. A page template is about as straight forward as it gets with WP. Either way, it’s still more than a couple lines of code. If you still find an incremental approach too much, or are just not interested, so be it. It’s not for everyone.

    Generally speaking, editing through import/export of spreadsheets would be considered a very poor solution because it all can be coded through PHP. But you have to go with what you know to some extent. If a spreadsheet solution works for you, go with it! The problem I see is to get the spreadsheet data back into the current meta data still would require bespoke code, so I don’t think you are gaining anything but more complication.

    Your only other alternative would be to bring in some professional help. Help can be found at https://jobs.wordpress.net/ or https://jetpack.pro/. Then you can get exactly what you want. If you allow that your own time has value, the net cost of employing help may not be all that expensive.

    Thread Starter anonymized-14293447

    (@anonymized-14293447)

    I thank you for your tips. Surely I’m keeping this thread for the time I will contact a devloper, as it’s clear I cannot get around it by myself.

    Concerning using a spreadsheet, I’m doing that because I plan to import everything with WP-All-Import plugin. You might know it: it’s basically a PHP-driven engine which allows to read an .xls file and assign each separate cells to their corresponding customfields. The great feature is also that you can edit on the fly your .xls file and when you import again it will just update previous entries. So, since my data/customfields can be exported as .csv/.xls then they can be re-imported again using that format. Do I feel lucky? ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘create customfield’s metabox in backend, out of an array’ is closed to new replies.