Forum Replies Created

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • in reply to: Post Relate Select Dropdown #7029
    catacaly
    Member

    That’s what’s happening, using the latest version.

    in reply to: Post Relate Select Dropdown #7023
    catacaly
    Member

    That only displays the default option, not the suppliers also 🙁

    in reply to: Post Relate Select Dropdown #7020
    catacaly
    Member

    I’m groggy right now but this is what I have so far for meta-boxes/product.php, which I threw together from some code found on these forums mixed with my own inferred:

    <?php
    /*
    Title: Supplier
    Post Type: product
    Context: side
    */
    
    piklist('field', array(
        'type' => 'post-relate'
    	,'field' => 'Supplier'
        ,'scope' => 'product_supplier'
    	,'field' => 'prod_supplier'
      ));
    
    /*
    $relate = get_posts(array(
        'post_type' => 'product_supplier' // Set post type you are relating to.
        ,'posts_per_page' => -1
    //    ,'post_belongs' => $post->ID
        ,'post_status' => 'publish'
        ,'suppress_filters' => false // This must be set to false
      ));
    
    foreach ($relate as $related):
      echo $related->post_title;
    endforeach;
    */
    
    //$scope = "'product_supplier'";
    
    	$posts = get_posts(array(
    		'post_type'			=> $scope,
    		'post_belongs'		=> $post->ID,
    		'post_per_page'	=> -1,
    		'suppress_filters'=> false
    	));
    
    	$default = get_post_meta( $post->ID, $field, true );
    	$default = empty($default) ? null : $default;
    
    	piklist('field', array(
    		'type'		=> 'select',
    		'scope'		=> 'relate',
    		'field'		=> $scope . '_select_post_id',
    		'template'	=> 'field',
    		'value'		=> $default,
    		'choices'	=> piklist(
    			get_posts(array(
    				'post_type'		=> 'product_supplier',//$scope,
    				'numberposts'	=> -1,
    				'orderby'		=> 'title',
    				'order'			=> 'ASC'
    			)),
    			array('ID', 'post_title')
    		),
    		'attributes'	=> array(
    			'class' => $scope . '_select_post_id'
    		)
    	));
    
    	piklist('field', array(
    		'type'	=> 'hidden',
    		'field'	=> $field,
    		'value'	=> $default,
    		'attributes' => array(
    			'class'	=> $field . '_select_id'
    		)
    	));
    
    	piklist('field', array(
    		'type'	=> 'hidden',
    		'scope'	=>	'relate',
    		'field'	=> $scope . '_select_relate',
    		'value'	=> 'has'
    	));
    
    	piklist('field', array(
    		'type'	=> 'hidden',
    		'scope'	=>	'relate',
    		'field'	=> $scope . '_select_relate_remove',
    		'attributes'	=> array(
    			'class' => $scope . '_select_relate_remove'	
    		)
    	));
      
      wp_reset_postdata();
    ?>
    
    <script type="text/javascript">
    
    	(function($) {
    
    		$(document).ready(function() {
    
    			var
    				$select = $('.<?php echo $scope . '_select_post_id'; ?>'),
    				initialValue = <?php echo ( $default) ? $default : -1 ; ?>;
    
    			$select.change(function(event) {
    				event.stopPropagation();
    
    				var
    					$remove = $('.<?php echo $scope . '_select_relate_remove'; ?>'),
    					$hiddenID = $('.<?php echo $field . '_select_id'; ?>'),
    					currentValue = $(this).val(),
    					ids = [];
    
    				if ( currentValue != initialValue ) {
    					$(this).children('option').each(function() {
    						var value = $(this).val();
    
    						if (value !== currentValue)
    							ids.push($(this).val());
    					});
    				}
    				$hiddenID.val(currentValue);
    				$remove.val(ids.join(','));
    			});
    
    		});
    
    	})(jQuery);
    </script>
    in reply to: Post Relate Select Dropdown #6986
    catacaly
    Member

    I changed the value for post_type < get_posts < choices < field, still yields blank. What else do I need to change? Also how do I add a null default option?

    in reply to: Post Relate Select Dropdown #6983
    catacaly
    Member

    How can I change this to a custom post type as the scope instead? I tried setting $scope = “‘my_cpt'”; didn’t work, options go blank.

    in reply to: Manufacturer/Model terms relationship/selection #2640
    catacaly
    Member

    The master field has got to switch what it updates the conditional field with depending on its own value… which has to be a variable self referenced?

    in reply to: Manufacturer/Model terms relationship/selection #2639
    catacaly
    Member

    Is there a way to pass the child terms to update the reliant model field with choices? instead of just a value?

    in reply to: wp-helpers.php #778 expects param 1 to be an a #2499
    catacaly
    Member

    Ok it’s only with the Show ALL options option checked… I like that option too…

    in reply to: wp-helpers.php #778 expects param 1 to be an a #2498
    catacaly
    Member

    The latter error appears twice after the first one below the admin bar and then once in each of these top-level admin menu list item elements: Dashboard, Comments, Profile, and Tools…

    catacaly
    Member

    Is there an easy-peasy-Piklist way of adding custom or default fields to admin columns?

    catacaly
    Member

    Thanks. I should’ve tried that.

    Same with show_admin_column, while you’re at it 🙂

    catacaly
    Member
    
    add_filter('piklist_post_types', 'listing_post_type');
    function listing_post_type($post_types)
    {
      $post_types['vessel'] = array(
        'labels' => piklist('post_type_labels', 'Listing')
        ,'title' => __('Enter boat name')
        ,'public' => true
    	,'hierarchical' => false
    	,'has_archive' => true
        ,'rewrite' => false/*array(
          'slug' => 'vessel'
        )*/
        ,'supports' => array(
    	  'title'
          ,'author'
          ,'revisions'
    	  ,'thumbnail'
    	  //,'editor'
    	  //,'excerpt'
        )
    	,'can_export' => true
        ,'edit_columns' => array(
            'title' => __('Name')
            ,'author' => __('Created by')
        )
        ,'hide_meta_box' => array(
          'slug'
          ,'author'
          //,'revisions'
          //,'comments'
          //,'commentstatus'
        )
    	,'post_states' => true
    	,'status' => array(
    		'draft' => array(
    		  'label' => 'Draft'
    		  ,'public' => false
    		)
    		,'active' => array(
    		  'label' => 'For Sale'
    		  ,'public' => true
    		)
    		,'inactive' => array(
    		  'label' => 'Inactive'
    		  ,'public' => false
    		)
    		,'contract' => array(
    		  'label' => 'Under Contract'
    		  ,'public' => true
    		)
    		,'sold' => array(
    		  'label' => 'Sold'
    		  ,'public' => true
    		)
    		,'expired' => array(
    		  'label' => 'Expired'
    		  ,'public' => false
    		)
    	)
        ,'capabilities' => array(
            'edit_post' => 'edit_listing',
            'edit_posts' => 'edit_listings',
            'edit_others_posts' => 'edit_others_listings',
            'publish_posts' => 'publish_listings',
            'read_post' => 'read_listing',
            'read_private_posts' => 'read_private_listings',
            'delete_post' => 'delete_listing'
        ) 
        ,'map_meta_cap' => true
      );
     return $post_types;
    }
    
    function apply_listing_caps() {
        // gets the administrator role
        $admins = get_role( 'administrator' );
    
        $admins->add_cap( 'edit_listing' ); 
        $admins->add_cap( 'edit_listings' ); 
        $admins->add_cap( 'edit_others_listings' ); 
        $admins->add_cap( 'publish_listings' ); 
        $admins->add_cap( 'read_listing' ); 
        $admins->add_cap( 'read_private_listings' ); 
        $admins->add_cap( 'delete_listing' ); 
    	
    	add_role( 'dd', 'DD', array(
    		'edit_listing' => true,
    		'edit_listings' => true,
    		'edit_others_listings' => true,
    		'publish_listings' => true,
    		'read_listing' => true,
    		'read_private_listings' => true,
    		'delete_listing' => false
    	));
    }
    add_action( 'admin_init', 'apply_listing_caps');
    
    add_filter('piklist_taxonomies', 'vessel_make_models');
    function vessel_make_models($taxonomies)
    {
       $taxonomies[] = array(
          'post_type' => 'vessel'
          ,'name' => 'make'
          ,'show_admin_column' => true
          ,'hide_meta_box' => true
          ,'configuration' => array(
            'hierarchical' => false
            ,'labels' => piklist('taxonomy_labels', 'Manufacturer')
            ,'show_ui' => true
            ,'query_var' => true
            ,'rewrite' => array( 
              'slug' => 'make' 
            )
          )
        );
       $taxonomies[] = array(
          'post_type' => 'vessel'
          ,'name' => 'model'
          ,'show_admin_column' => true
          ,'hide_meta_box' => true
          ,'configuration' => array(
            'hierarchical' => false
            ,'labels' => piklist('taxonomy_labels', 'Model')
            ,'show_ui' => true
            ,'query_var' => true
            ,'rewrite' => array( 
              'slug' => 'model' 
            )
          )
        );
    	return $taxonomies;
    }
    
    catacaly
    Member

    Along the lines of what I had in mind…

    Although, this site is supposed to have hundreds-thousands of listings that each hold a good amount of data. In addition to make/model there are some other fields that should be searchable/filterable/browseable, not unlike taxonomies; but make/model will have more options than the others which is why I’m focusing on them.

    But in terms of performance, should I perhaps avoid using taxonomies altogether, to keep the metadata consistent in form, too? Maybe instead of taxonomies the makes/models can just be managed from the CPT’s settings? What would you (anyone) suggest as a more optimal approach?

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