Custom Fields
Re-Envisioned
Support Meta Box Group Auto-populate field

This topic contains 10 replies, has 2 voices, and was last updated by  account@servicioexpreso.com 2 months, 1 week ago.

  • Creator
    Topic
  • #16064

    I should to create two custom fields (author and CPT). How to set that it can be auto-populated by current post.

    1) Author should be populated by full name of author of current post.
    2) CPT should be populated by current post type (I have 11).

Viewing 10 replies - 1 through 10 (of 10 total)
  • Author
    Replies
  • #16088

    Anh Tran
    Keymaster

    Hi,

    Doesn’t the std settings work? You can get the current post info (post ID is grabbed from $_GET) and put the post info in the std settings for the fields.

    #16103

    Sory, but no idea. I have this code and it could works just fine if could be auto-populated, but no idea what code to add to all 3 fields. Can you please, ‘fix’ the code?

    P.S. – It is about (for me) weird fact how there is no (simple) option to display and filter posts by those 3 ‘arguments’. Closest (cheap) solution what I found is JetSmartFilter and to display/filter it trough mix of taxonomies and custom fields.

    https://pastebin.com/DMNhiiUe

    #16104

    I forgot, if it is easier for taxonomy, works also with CrocoBlocks.

    #16111

    Anh Tran
    Keymaster

    Here is the code with std:

    https://pastebin.com/QHaMAXY2

    Regarding filtering results on the front end, please use a search & filter plugin like FacetWP. We support FacetWP via a free extension.

    #16122

    Thanks, but unfortunately not working. There are couple of problems here, but first full code.

    https://pastebin.com/MguvyWy4

    FIRST PROBLEM

    Post can be published without fields filling (originally created by MB).

    SECOND PROBLEM

    Post can be published without fields filling (AIO disabled and added your code at top).

    THIRD PROBLEM

    It not fill anything.

    REMARK

    1) Is it such kind of code for Taxonomy, as there I will not need to get installed MB on my client site (for me, for filtration works also Taxonomy)? Actually, for me will be much better for Taxonomy. ie

    https://pastebin.com/bQvsBgyK

    2) FacetWP, year but I’m from Ecuador and I cannot to afford it. JetSmartFilters – Unlimited Sites is only $31 (vs $249) with incomparable smaller code. I can agree how FacetWP is probably best, but … I think that they are lost in pricing. Whatever.

    #16126

    Anh Tran
    Keymaster

    Hi,

    1st and 2nd problem: I guess you’re using Gutenberg, thus the required parameter doesn’t work, because WordPress submits values via Ajax. Until now, there’s no solution for that yet.

    3rd problem: I see you miss std from my code, so of courses, fields are not filled.

    Regarding the filter: you might want to try Search & Filter plugin. It’s free on wordpress.org.

    #16134

    1) REQUIRED

    Yes, I’m using Gutenberg. However, I figured (I guess correctly) how it is 100% irrelevant in my case as it should to be auto-populated.

    2) STD

    You are right that I missed, but it still not works. I tried with both version (what I know) to insert it, but not working. Code is (intentionally mixed two variations) as

    https://pastebin.com/kUNCMQpJ

    3) TAXONOMY

    You missed that I would actually like much more if that will be taxonomy solution, than custom fields. Is it possible to do with taxonomy (how should to look code for author (ie)?

    4) FILTRATION

    You are right. That is certainly best option vs pricing (my opinion), but as blog is on Elementor and CrocoBlocks grounded (in any case), natural solution is to using JetSmartFilters as part of bundle.

    #16135

    3) Taxonomy (additional)

    As I wrote, as I already using CrocoBloks for client and there is already active JetEngine (but my CPTs are done by MB php in child theme) vs ‘Listings’, there is no sense to add MB as well just because of Custom Fields for filtration. I guess how you now understand why I would prefer taxonomy auto-populate solution (if it is possible).

    #16145

    Anh Tran
    Keymaster

    Hi,

    Regarding std, I see you put it under query_args which is wrong and set it empty. Can you try this code (I modified your latest code)?

    https://pastebin.com/tuzF9LHD

    Regarding the taxonomy issue: if you want to use taxonomy, then you have to create the taxonomy first. I don’t see any reason for date, author or post type should be taxonomies. This is a post I wrote about custom fields vs. custom taxonomies. Maybe it helps.

    #16162

    1) I intentionally set both options for std and problem was in empty value. So, now works PERFECT. Thanks.

    2) I’m afraid how I will need to do it with Custom Taxonomy, as it looks how JetSmartFilters supports only CFds created by its own JetEngine (where I cannot set auto-populate). So, please, if you can, help here also. Code is (just author, as I guess that I will figure than):

    function your_prefix_register_taxonomy() {
    
        $args = array (
            'label' => esc_html__( 'Autores de la publicación', 'text-domain' ),
            'labels' => array(
                'menu_name' => esc_html__( 'Autores de la publicación', 'text-domain' ),
                'all_items' => esc_html__( 'All Autores de la publicación', 'text-domain' ),
                'edit_item' => esc_html__( 'Edit Autor de la publicación', 'text-domain' ),
                'view_item' => esc_html__( 'View Autor de la publicación', 'text-domain' ),
                'update_item' => esc_html__( 'Update Autor de la publicación', 'text-domain' ),
                'add_new_item' => esc_html__( 'Add new Autor de la publicación', 'text-domain' ),
                'new_item_name' => esc_html__( 'New Autor de la publicación', 'text-domain' ),
                'parent_item' => esc_html__( 'Parent Autor de la publicación', 'text-domain' ),
                'parent_item_colon' => esc_html__( 'Parent Autor de la publicación:', 'text-domain' ),
                'search_items' => esc_html__( 'Search Autores de la publicación', 'text-domain' ),
                'popular_items' => esc_html__( 'Popular Autores de la publicación', 'text-domain' ),
                'separate_items_with_commas' => esc_html__( 'Separate Autores de la publicación with commas', 'text-domain' ),
                'add_or_remove_items' => esc_html__( 'Add or remove Autores de la publicación', 'text-domain' ),
                'choose_from_most_used' => esc_html__( 'Choose most used Autores de la publicación', 'text-domain' ),
                'not_found' => esc_html__( 'No Autores de la publicación found', 'text-domain' ),
                'name' => esc_html__( 'Autores de la publicación', 'text-domain' ),
                'singular_name' => esc_html__( 'Autor de la publicación', 'text-domain' ),
            ),
            'public' => true,
            'show_ui' => true,
            'show_in_menu' => true,
            'show_in_nav_menus' => true,
            'show_tagcloud' => false,
            'show_in_quick_edit' => false,
            'show_admin_column' => false,
            'show_in_rest' => true,
            'hierarchical' => false,
            'query_var' => true,
            'sort' => false,
            'rewrite_no_front' => false,
            'rewrite_hierarchical' => false,
            'rewrite' => true,
        );
    
        register_taxonomy( 'autor-de-la-publicacion', array( 'noticias', 'articulos', 'cuentos', 'estudios', 'regalos', 'encuestas', 'ejercicios-web', 'podcasts', 'webcasts', 'seminarios-web', 'reciclados' ), $args );
    }
    add_action( 'init', 'your_prefix_register_taxonomy', 0 );
Viewing 10 replies - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.