Viewing 15 replies - 1 through 15 (of 21 total)
  • I am also interested.

    my current hack with jquery css is:

    ======
    Custom Field template:
    ——

    [Books]
    type = select
    value = categoryA # categoryB
    label = Books
    search = true
    output = true
    
    [Books_categoryA]
    size = 35
    type = text
    label = CategoryA
    search = true
    output = true
    
    [Books_categoryB]
    size = 35
    type = text
    label = CategoryB
    search = true
    output = true

    =======
    jquery for the backend:
    ——-

    $("#books1_0").change(function () {
              var str = "";
              $("#books1_0 option:selected").each(function () {
                    str += $(this).text() + " ";
                  });		
    
            $("#dl_category12_0").removeClass("select");
    		$("#dl_books_categoryA2_0").removeClass("select");
    		$("#dl_books_categoryA2_0").removeClass("CategoryA");
    		$("#dl_books_categoryA2_0").removeClass("CategoryB");
    
    		$("#dl_books_categoryB3_0").removeClass("select");
    		$("#dl_books_categoryB3_0").removeClass("categoryA");
    		$("#dl_books_categoryB3_0").removeClass("categoryB");
    
    		$("#dl_books_categoryA2_0").addClass(str);
    		$("#dl_books_categoryB3_0").addClass(str);
    
        })
            .trigger('change');

    =======
    CSS for the backend:
    ——-

    #dl_books_categoryA2_0			{display:none;}
    #dl_books_categoryB3_0			{display:none;}
    #dl_books_categoryA2_0.category1	{display:block;}
    #dl_books_categoryB3_0.category2	{display:block;}

    This solution is very unprofessional, but I have found no other way.
    I am very much interested to find another solution, thanks.

    Thread Starter Derek Ashauer

    (@sccr410)

    What I’m looking for has nothing to do with JS or CSS, I want to populate a select list from items in the database. For example, I want to do a “related product”, so I want to pull all the products from the database to generate a select list.

    yes absolutely. Use the type=select and code option. I have used:

    [Programmes]
    type = select
    code = 0
    multiple = true
    multipleButton = true

    I then put this into the PHP Code section of the plugin options (in code #0):

    <?php
    global $wpdb;
    $items = $wpdb->get_results("SELECT ID, post_title
    FROM $wpdb->posts
    where post_type = 'programmes'
    and post_status = 'publish'
    order by post_title ASC");
    $i = 0;
    foreach ($items as $item) {
    	$values[$i] = $item->ID;
    	$valueLabel[$i] = $item->post_title;
    	$i++;
    } ?>

    Of course you just change the code = 0 line to whatever the relevant code snippet identifier is.

    Thread Starter Derek Ashauer

    (@sccr410)

    Perfect! I had no idea what code = 0 was for, there is no documentation on it.

    Yeah this plugin sadly is quite light on documentation, but we’ve just launched a HUUUGE project that uses Custom Field Templates quite extensively, so if you have any more issues, just sing out!

    Thread Starter Derek Ashauer

    (@sccr410)

    Thanks so much!

    @brenfm,

    I am researching this plugin to meet the specs for a client and I wonder if you would be so kind as to advise off forum on whether this plugin will meet our needs.

    I can be reached through the contact form here. (not sure where to contact you)

    If I can confirm that this plugin will work for this project (without details of exactly how), I can pay for any additional advisement if necessary.

    Done! Look forward to hearing from you

    pauro

    (@pauro)

    Hi,glad to found this thread
    I have tried to use code from Bren (thank you), and change it a bit to

    global $wpdb;
    $items = $wpdb->get_results("SELECT ID, post_title
    FROM $wpdb->posts
    where post_type = 'page'
    and post_status = 'publish'
    and post_parent = '60'
    order by post_title ASC");
    $i = 0;
    foreach ($items as $item) {
    	$values[$i] = $item->ID;
    	$valueLabel[$i] = $item->post_title;
    	$i++;
    }

    it works nice, showing page titles from parent ’60’ in the select box. Unfortunately I need to show more child pages from other parent. I have tried to do it like this:
    and post_parent = '60,100'
    and this
    and post_parent = ('60' , '100')
    but no luck. Any suggestion?

    BrenFM

    (@brenfm)

    This is straight SQL, so what you’ll probably need to do the following (untested sorry, but worth a shot!):

    and (post_parent = '60' OR post_parent = '100')

    or maybe:

    and ((post_parent = '60') OR (post_parent = '100'))

    One of them should work, I would hope!

    You could then order them by

    order by post_parent,post_title

    …if you wanted them sorted by the parent page first.

    Hope that helps!

    pauro

    (@pauro)

    Hi Bren, thank you, it helps
    For a sake of discussion, I have also tried:
    and post_parent in (60,100,200)
    and it also works (at least in my localhost).
    I’m just a beginner so my silly question is, which is better or safer?

    BrenFM

    (@brenfm)

    ahhhhh of course… IN! much easier to use in… especially if planning to expand your selection of parent pages. And I would think quicker (marginally) from an SQL point of view.

    pauro

    (@pauro)

    So I assume that using “IN” is okay. I have to make sure because I am really a newbie in this SQL thing and this “IN” thing I have found by the help of uncle google πŸ™‚ . Hopefully this will also help others.

    Thank you Bren.

    Next, I want to make this dynamic select function used as Chained Select Box. I have start a new thread here.

    Hopefully you also can help cracking the codes.

    thanks

    I just visited this topic and tried the trick which seem to work like a charm and I thank you for sharing that πŸ˜€

    However, I’ve tried to replace the post type with taxonomy in the following example to pull out taxonomy values for “languages” to dynamically be used in a Select field but it does not pull the values. I appreciate any directions in case anyone would help me out with this problem.

    global $wpdb;
    $items = $wpdb->get_results("SELECT ID, term_title
    FROM $wpdb->term
    where term= 'sprak'
    and post_status = 'publish'
    order by the_term_title ASC");
    $i = 0;
    foreach ($items as $item) {
    	$values[$i] = $item->ID;
    	$valueLabel[$i] = $item->the_term_title;
    	$i++;
    }

    Taxonomies are stored in a completely different database table (as your code shows), so the idea of using “publish” won’t work as there is no field called “post_status” in the terms table.

    I think you are trying to overcomplicate things. Post meta is post meta and taxonomies are best left well separate to this. If you are looking to associate a taxonomy with a post/page/custom content type then look into the Custom Post Type UI plugin. You can make custom post types and taxonomies with a UI and then associate the taxonomies with a given post type… then you’ll get a taxonomy box (like categories or tags in a normal post) when editing your content type.

Viewing 15 replies - 1 through 15 (of 21 total)

The topic ‘[Plugin: Custom Field Template] Dynamic select list’ is closed to new replies.