Forum Replies Created

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • in reply to: post to user relationships #6157

    Ok, it’s closer but not finnished.

    I have these data:
    ——————
    CPT: rf_shows
    name Sendung1
    id: 20

    CPT: rf_episode
    name: Folge1
    id: 38

    User
    name: Hans
    id: 2

    With this code:

    
    <?php
    /*
    Title: Sendeplanung
    Post Type: rf_episode
    */
    
    piklist('field', array(
      'type'      => 'checkbox',
      'label'     => 'Shows',
      'relate'    => array(
        'scope'     => 'post'
      ),
      'choices'   => piklist(get_posts(array(
        'post_type'   => 'rf_show',
        'numberposts' => -1,
        'orderby'     => 'title',
        'order'       => 'ASC'
      )), array('ID', 'post_title'))
    ));
    
    piklist('field', array(
      'type'      => 'checkbox',
      'label'     => 'DJs',
      'relate'    => array(
        'scope'     => 'user'
      ),
      'choices'   => piklist(get_users(array(
        'orderby'     => 'display_name',
        'order'       => 'ASC'
      )), array('ID', 'display_name'))
    ));
    

    I get in wp_postmeta:

    
    post_id: 20
    meta_key: __relate_post
    meta_value: 38
    

    and in wp_usermeta:

    
    user_id: 2
    meta_key: __relate_post
    meta_value: 38
    

    Thats OK. But I did not see the user checked in post editor although the database entry is correct (look at the attachment).

    Is my use of post-to-user relationship wrong?

    Attachments:
    You must be logged in to view attached files.
    in reply to: post to user relationships #6133

    Hi Jason,

    yes, there is no __relate_post entry in the database and I’m looking directly in the mysql database. I get the __relate_post entry only as long as I give a ‘field’ parameter.

    in reply to: post to user relationships #6126

    Yes, this works, it’s the same like the first field in my first post where I wrote that this works. It works bidirectional in the sense that I get two entries in the postmeta table:

    – one that links to the selected post ID of post type ‘rf_show’:
    post_id: 528
    meta_key: my_relate
    meta_value: 38

    – and the second that links back (comes from the ‘relate’ parameter):
    post_id: 38
    meta_key: __relate_post
    meta_value: 528

    Maybe I’m not precise in my question. My point is that using the same code for a post-to-user relationship I get only one entry in the database. The ‘relate’ parameter does nothing in this case (look my second field in the first post). I get no back-link entry in the database.

    Jason said, that I don’t need the back-link, which is true, but it’s confusing that the post-to-post and post-to-user relationship differs on this point. Following this approach (we need only one meta entry) the ‘relate’ parameter is unnecessary.

    Then Jason said we should omit the ‘field’ parameter if we use the ‘relate’ parameter, but this
    does not work.

    So I think I use the following ‘classical’ approach without the ‘relate’ parameter but with a ‘field’ parameter:

    
    piklist('field', array(
        'type' => 'select'
        ,'field' => 'my_relate'
        ,'template'  => 'field'
        ,'label' => 'Relate Posts'
        ,'choices' => piklist(
          get_posts(array(
            'post_type' => 'rf_show'
            ,'numberposts' => -1
            ,'orderby' => 'title'
            ,'order' => 'ASC'
          ))
          ,array('ID', 'post_title')
        )
        ,'attributes'=> array(
          'multiple'  => 'multiple'
        )
      ));
    

    Regards

    in reply to: post to user relationships #6115

    Sorry, no. Does not work. Get no database entries. This is the full code:
    1. post types in own plugin

    
    add_filter('piklist_post_types', 'rf_post_types');
    function rf_post_types($post_types)
    {
      $post_types = array_merge($post_types, array(
        // post type for shows:
        'rf_show' => array(
          'title' => 'enter show name...',
          'menu_icon' => plugins_url('radiofrei/images/rf-menu-icon.png'),
          // labels
          'labels' => array(
            'name' => 'Shows',
            'singular_name' => 'Show'
          ),
          // wordpress features
          'supports' => array(
            'title',
            'editor',
            'revisions'
          ),
          // columns in admin
          'edit_columns' => array(
            'title' => 'Shows'
          ),
          // frontend - backend
          'public' => true,
          // slug
          'rewrite' => array(
            'slug' => 'shows'
          )
        ),
    
        // post type for episodes:
        'rf_episode' => array(
          'title' => 'enter episode name...',
          'menu_icon' => plugins_url('radiofrei/images/rf-menu-icon.png'),
          // labels
          'labels' => array(
            'name' => 'Episodes',
            'singular_name' => 'Episode'
          ),
          // wordpress features
          'supports' => array(
            'title',
            'editor',
            'comments',
            'revisions'
          ),
          // columns in admin
          'edit_columns' => array(
            'title' => 'Episode'
          ),
          // frontend - backend
          'public' => true,
          'has_archive' => true,
          // slug
          'rewrite' => array(
            'slug' => 'episodes'
          )
        )
      ));
      return $post_types;
    }
    

    2. Metabox for rf_episode

    
    <?php
    /*
    Title: Related Shows
    Post Type: rf_episode
    */
    piklist('field', array(
      'type'      => 'select',
      'template'  => 'field',
      'choices'   => piklist(get_posts(array(
        'post_type'   => 'rf_show',
        'numberposts' => -1,
        'orderby'     => 'title',
        'order'       => 'ASC'
      )), array('ID', 'post_title')),
      'relate'    => array(
        'scope'     => 'post'
      ),
      'attributes'=> array(
        'multiple'  => 'multiple'
      )
    ));
    

    I see all my shows and can select one/multiple but after saving no selection(s) and no database entries.

    in reply to: post to user relationships #6110

    Thanks Jason for the answer.
    It makes things clearer now for me but not clear enough (the ‘we need no field parameter’ part, later). If I understand relationships right in 0.9.9.x they are not bidirectional in the sense that piklist would make two database entries for the relationship. Instead there is only one entry in a meta table (postmeta or usermeta) which links the IDs and the use of the parameters you mention ‘user_has’,’user_belongs’, ‘post_has, ‘post_belongs’ etc.

    What confused me was that there were two entries in the postmeta table in my first post-to-post example and I expected the same for the post-to-user relationship. The code for this is from the demo /piklist/add-ons/piklist-demos/parts/meta-boxes/field-relate.php and there IS a field parameter.

    A search for ‘relate’ => array in the piklist folder gives three results:
    /piklist/add-ons/piklist-demos/parts/meta-boxes/field-relate.php
    /piklist/add-ons/piklist-demos/parts/meta-boxes/field-relationship.php
    /piklist/parts/fields/post-relate.php

    In field-relate.php and post-relate.php are ‘field’ parameters, in field-relationship.php not.

    Now following the demo field-relationship.php I see there are 3 fields of ‘type’ => ‘group’ with no ‘field’ parameter.

    Based on this here is my test post-to-user code with a field of type ‘group’ that works:

    
    piklist('field', array(
    	'type' => 'group',
    	'scope' => 'user',
    	'label' => __('DJs', 'rf'),
    	'relate' => array(
    		'scope' => 'post'
    	),
    	'fields' => array(
    		array(
    			'type' => 'checkbox',
    			'field' => 'ID',
    			'choices' => piklist(
    				get_users(array(
    					'orderby' => 'display_name',
    					'order' => 'ASC'
    				)),
    				array('ID', 'display_name')
    			)
    		)
    	)
    ));
    

    This way I get entries in the usermeta table (links the selected user IDs to the Post ID).

    But how should the code look in a non ‘group’ field type? Transforming to this does not work:

    
    piklist('field', array(
    	'type' => 'checkbox',
    	'scope' => 'user',
    	'label' => __('DJs', 'rf'),
    	'relate' => array(
    		'scope' => 'post'
    	),
    	'choices' => piklist(
    		get_users(array(
    			'orderby' => 'display_name',
    			'order' => 'ASC'
    		)),
    		array('ID', 'display_name')
    	)
    ));
    

    No database entries.

    So an example of how to use the ‘relate’ parameter in an ordinary field would be very helpfull.

    in reply to: post to user relationships #6105

    No solution? Is there a bug tracker somewhere?

    regards
    Steffen

    in reply to: post to user relationships #6082

    Thanks for replying, but…


    @Jason

    Sorry, but no. I need the ‘field’ parameter. Removing the ‘field’ parameter results in no database entries at all, means nothing is stored in the database. I think you get confused with the use of the field type ‘post-relate’ where I not have to give a field parameter because its done in the definition of ‘post-relate’ in /piklist/parts/fields/post-relate.php. But since I use the field type ‘checkbox’ I have to give a ‘field’ parameter. And thats Ok and works in the post to post relationship part.


    @jrcreative

    No, have tried that all, no success. Notice that we talk not about the ‘scope’ parameter but the use of scope in the ‘relate’ parameter. Look at the definition of ‘post-relate’ in /piklist/parts/fields/post-relate.php:

    
    <div class="wp-tab-panel">
      
      <?php
        piklist('field', array(
          'type' => 'checkbox'
          ,'scope' => 'post_meta'
          ,'field' => '_' . piklist::$prefix . 'relate_post'
          ,'object_id' => $arguments['object_id']
          ,'choices' => piklist(
            get_posts(array(
              'post_type' => $scope
              ,'numberposts' => -1
              ,'orderby' => 'title'
              ,'order' => 'ASC'
            ))
            ,array('ID', 'post_title')
          )
          ,'relate' => array(
            'scope' => 'post'
          )
        ));
      ?>
    
    </div>
    

    The use of ‘scope’ => ‘post’ in the ‘relate’ parameter results in storing the relationship in the postmeta table which is the expected behavior.

    Problem is that I get no entry in the usermeta table.

    in reply to: post to user relationships #6074

    Thank you, but no, doesn’t work.

    I think this is not the problem here because ‘scope’ is a piklist term that will be used to finally store the realtion in the corresponding meta table. As you see in my post the ‘scope’ => ‘post’ results in saving the relation correctly in the postmeta table. Piklist should do it in the same way with ‘scope’ => ‘user’ and save the data in usermeta.

    in reply to: hide fields until layout is ready #5749

    OK, I will be watching that for side effects.
    Thanks.

    in reply to: hide fields until layout is ready #5745

    Ok, following your hint and the Information here I have found a way to display the settings form after all fields are on the right place and conditionally displayed or hidden:

    1. Create hide-form-table.css

    
    /*
     hide <table class="form-table"> (class used for wordpress settings pages)
    */
    .form-table {
    	display:none; 
    }
    

    2. Create show-form-table.js

    
    /*
     on document.ready show <table class="form-table">
    */
    (function($) {
        $(document).ready(function() {
        	$(".form-table").show();
        });
    })(jQuery);
    

    3. Add script and style to my-plugin.php or theme (functions.php)

    
    // javascript and css to initially hide class form-table and show it on document.ready
    add_filter('piklist_assets', 'my_assets');
     
    function my_assets($assets)
    {
      array_push($assets['scripts'], array(
        'handle' => 'my-javascript',
        'src' => plugins_url('my-plugin/js/show-form-table.js'),
        'ver' => '1.0',
        'deps' => 'jquery',
        'enqueue' => true,
        'in_footer' => true,
        'admin' => true,
        'front' => false
      ));
     
      array_push($assets['styles'], array(
        'handle' => 'my-admin-styles',
        'src' => plugins_url('my-plugin/css/hide_form_table.css'),
        'ver' => '1.2',
        'enqueue' => true,
        'in_footer' => true,
        'admin' => true,
      ));
     
      return $assets;
    }
    

    To make it better I have to add some kind of loading hint. This is not really nice but it works for me. One thing I have missed: there is no own class or id for the entire piklist settings form so I have to use form-table class which is used by all other wordpress settings pages too. If you want to use this on other pages or posts you have to use other css id’s or classes.

    Thanks.

    in reply to: remove fields from post type #5564

    Thank you, it’s working just fine. I can remove meta-boxes from post, page and custom post types using the wordpress IDs for meta-boxes:
    https://codex.wordpress.org/Function_Reference/remove_meta_box#Parameters

    But some questions remain:
    – Can I remove e.g. the post title this way?
    – What do you mean with “fields section”?
    – Can I use the ‘extend’ feature to remove fields from User Profiles?

    Thanks!

Viewing 11 posts - 1 through 11 (of 11 total)