Forum Replies Created

Viewing 15 replies - 61 through 75 (of 158 total)
  • Hmm, so I should be ok to use $_GET[“myvar”] on the template page? I’ll do some debugging when I get chance…

    Hi Viljami, is your response to address the querystring question or the logged in data question?

    Thanks

    candell

    (@candell)

    Hi guys, how are you grabbing the values, I tried $_GET[“myvar”]; without success.

    Also, are POST methods out, are we limted to GET?

    Thread Starter candell

    (@candell)

    Got it thanks

    Thread Starter candell

    (@candell)

    Hi

    Thanks for the amazing support, how do I actually do that?

    Thanks again

    Thread Starter candell

    (@candell)

    That’s great thanks Jonathan. It does work and will be great for most, could I please ask another question.

    I am modifying the query via pre_get_posts;

    add_filter( 'pre_get_posts', 'jobs_query_for_beautiful_filters' );
    function jobs_query_for_beautiful_filters( $query ) {
    	$timecutoff = date("Ymd");
    	
    	
    	 if ( (! is_post_type_archive('sc_jobs') ) && ( ! is_tax( 'job_categories' ) ) && ( ! is_tax( 'the_advertiser' ) ) || is_admin() ) {
    	
    		return;
    	};
        
    	
    	$query->set( 'post_type', 'sc_jobs' );
    	$query->set( 'orderby', 'meta_value' );
    	$query->set( 'meta_key', 'closing_date' );
    	$query->set( 'meta_compare', '>=' );
    	$query->set( 'meta_value', $timecutoff );
    	$query->set( 'order', 'ASC' );
    }

    to take in to account the closing date meta. The job page search options take this in to account and show the correct counts, however the fixed header search options show numbers disregarding the modified query so the post counts do not match.

    Thread Starter candell

    (@candell)

    Thanks bcworkz.

    The reason for not using WP_Query was simple, I didn’t know how to build up the query using it (I can do simple queries however), hence using plain old sql.

    If you don’t mind, how would you create the above query using WP_Query?

    Thanks

    Thread Starter candell

    (@candell)

    Thanks, got it

    Thread Starter candell

    (@candell)

    Aha I’m almost there!

    A while ago I added a script to prevent the display of my jobs post type if a meta I had set for the closing date had passed.

    It is also working in admin, how do I make the below I added to my functions file only work on the front end, not admin?

    add_filter( 'pre_get_posts', 'jobs_query_for_beautiful_filters' );
    function jobs_query_for_beautiful_filters( $query ) {
    	$timecutoff = date("Ymd");
    	
    	
    	 if ( (! is_post_type_archive('sc_jobs') ) && ( ! is_tax( 'job_categories' ) ) ) {
    	
    		return;
    	};
        
    	
    	$query->set( 'post_type', 'sc_jobs' );
    	$query->set( 'orderby', 'meta_value' );
    	$query->set( 'meta_key', 'closing_date' );
    	$query->set( 'meta_compare', '>=' );
    	$query->set( 'meta_value', $timecutoff );
    	$query->set( 'order', 'ASC' );
    }

    Thanks

    Thread Starter candell

    (@candell)

    Hi, I’m not sure which you mean I should set.

    Thread Starter candell

    (@candell)

    Thanks bcworkz, do you know why admins and editor users do not see all jobs, they have the cap set

    $admins1->add_cap( ‘edit_others_jobs’ );

    Thread Starter candell

    (@candell)

    Got it working, thank you Jonathan

    Thread Starter candell

    (@candell)

    Thanks for the reply Jonathan, I am struggling to get this to work with pre_get_posts (and thanks for educating me to this filter, I can see many uses for it going forwards).

    Here’s my function

    add_filter( 'pre_get_posts', 'jobs_query_for_beautiful_filters' );
    function jobs_query_for_beautiful_filters( $query ) {
    $timecutoff = date("Ymd");
    	
    $jobsquery = array(
    array(
    'post_type' => 'sc_jobs',
    'orderby' => 'meta_value',
    'meta_key' => 'closing_date',
    'meta_compare' => '>=',
    'meta_value' => $timecutoff,
    'order' => 'ASC'
    )
    );
    $query->set( 'jobs_query', $jobsquery );
    }
    

    The posts to display are located in my archive-cptjobs.php file displaying the loop for the custom post type which is now using

    <?php do_action('show_beautiful_filters'); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    etc etc

    However posts with a past date are still showing.

    Thanks

    I think my issue may be partly due to how the custom post type (CPT) has been set up. I have created a new user role ‘authority’, when they log in, all they should see is the Job CPT and also just view their own jobs/posts.

    It seems to be working great apart from the fact they cannot tick any taxonomies.

    Here’s my CPT, maybe there is something obvious in there that I am missing

    <?php
    /**
     * Custom post type for jobs and taxonimies
     */
     
    add_action( 'init', 'create_custom_post_types' );
    function create_custom_post_types() {
    	
    
    	register_post_type( 'sc_jobs',
    		array(
    			'labels' => array(
    					'name' => 'Job',
    					'singular_name' => 'Job',
    					'add_new' => 'Add New',
    					'add_new_item' => 'Add New',
    					'edit_item' => 'Edit',
    					'new_item' => 'New',
    					'all_items' => 'All Jobs',
    					'view_item' => 'View',
    					'search_items' => 'Search',
    					'not_found' =>  'No jobs found',
    					'not_found_in_trash' => 'No jobs found in Trash',
    					'parent_item_colon' => '',
    					'menu_name' => 'Jobs'
    			),
    			'public' => true,
    			'has_archive' => true,
    			'rewrite' => array('slug' => 'job'),
    			'capability_type' => 'job',
    			'capabilities' => array(
    				'publish_posts' => 'publish_jobs',
    				'edit_posts' => 'edit_jobs',
    				'edit_others_posts' => 'edit_others_jobs',
    				'delete_posts' => 'delete_jobs',
    				'delete_others_posts' => 'delete_others_jobs',
    				'read_private_posts' => 'read_private_jobs',
    				'edit_post' => 'edit_jobs',
    				'delete_post' => 'delete_jobs',
    				'read_post' => 'read_jobs',
    				'assign_terms'  => 'edit_taxo'
    			),
    			'supports' => array('title', 'editor', 'thumbnail')
    		)
    	);
    	
    	register_taxonomy(
    		'job_categories',
    		array('sc_jobs'),
    		array(
    			'hierarchical' => true,
    			'label' => __( 'Job Categories' ),
    			'rewrite' => array( 'slug' => 'job-category' ),
    			'show_ui' => true,
    			'query_var' => 'job-category',
    		)
    	);
    
    	register_taxonomy(
    		'contract_type',
    		array('sc_jobs'),
    		array(
    			'hierarchical' => true,
    			'label' => __( 'Contract type' ),
    			'rewrite' => array( 'slug' => 'job-contract-type' ),
    			'show_ui' => true,
    			'query_var' => 'job-contract-type',
    		)
    	);
    
    	register_taxonomy(
    		'working_pattern',
    		array('sc_jobs'),
    		array(
    			'hierarchical' => true,
    			'label' => __( 'Working Pattern' ),
    			'rewrite' => array( 'slug' => 'job-working-pattern' ),
    			'show_ui' => true,
    			'query_var' => 'job-working-pattern',
    		)
    	);
    
    	register_taxonomy(
    		'salary_band',
    		array('sc_jobs'),
    		array(
    			'hierarchical' => true,
    			'label' => __( 'Salary Band' ),
    			'rewrite' => array( 'slug' => 'salary-band' ),
    			'show_ui' => true,
    			'query_var' => 'salary-band',
    		)
    	);
    	
    	register_taxonomy(
    		'the_advertiser',
    		array('sc_jobs'),
    		array(
    			'hierarchical' => true,
    			'label' => __( 'Advertiser' ),
    			'rewrite' => array( 'slug' => 'job-advertiser' ),
    			'show_ui' => true,
    			'query_var' => 'job-advertiser',
    		)
    	);
    	
    	
    }
    
    function add_jobs_caps() {
       
        $admins = get_role( 'authority' );
    
        $admins->add_cap( 'edit_jobs' );  
        $admins->add_cap( 'publish_jobs' ); 
        $admins->add_cap( 'read_jobs' ); 
        $admins->add_cap( 'read_private_jobs' ); 
        $admins->add_cap( 'delete_jobs' ); 
    	$admins->add_cap( 'edit_taxo' );
    	$admins->remove_cap( 'edit_others_jobs' );
    	$admins->remove_cap( 'delete_others_jobs' );
    	
    	
    }
    add_action( 'admin_init', 'add_jobs_caps');
    
    function add_jobs_caps1() {
       
        $admins1 = get_role( 'administrator' );
    
        $admins1->add_cap( 'edit_jobs' );  
        $admins1->add_cap( 'publish_jobs' ); 
        $admins1->add_cap( 'read_jobs' ); 
        $admins1->add_cap( 'read_private_jobs' ); 
        $admins1->add_cap( 'delete_jobs' ); 
    	$admins1->add_cap( 'edit_others_jobs' );
    	$admins1->add_cap( 'delete_others_jobs' );
    	
    }
    add_action( 'admin_init', 'add_jobs_caps1');
    
    		
    ?>

    Great little script, I limited all but admins to view others posts, works great.

    However, on a custom post type, I have set several taxononies and all users need to be able to tick the correct options per post, however with this script running the taxonomy checkboxes are greyed out.

Viewing 15 replies - 61 through 75 (of 158 total)