Skip Navigation

[Résolu] Corrupted installation?

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 13 réponses, has 2 voix.

Last updated by Eric Il y a 7 années et 11 mois.

Assigned support staff: Caridad.

Auteur
Publications
#143719

Hi there,

I'm developing a site that imports a jobs feed into a custom post type. I have a search page for those jobs posts that was working just fine at one point. Now, for some reason, the search box no longer returns results. Well, stranger than that, it returns results of other custom post types, which aren't selected in the view query. It should only be retuning jobs. The taxonomy filters do indeed only return jobs custom post types. That part still works...

I had a feeling something weird was going on, not just an oversight in a view, so I exported my Types and Views then imported them into a Discover-WP site. I added the view to a page. It works perfectly. Why would the same Types and Views not work on my dev site?

Here's the Discover-WP URL: hidden link
I added a few sample jobs. Searching for 'lion' or 'monkey' will return results.

Here's my dev site: hidden link
Using the search box won't return Job posts. Strangely, it'll return results from the Articles and Case Study custom post types. Although you can't see them in the table unless you look in the source code.

Please help as soon as possible. I have a deadline rapidly approaching and this is a key component.

Thanks!
Eric

#143809

I'm also having trouble filtering post types by the built-in category taxonomy.

Here's a test page:
hidden link
The search box works, as does the tag filter.
What am I doing wrong with the category filter?

Here's the dev project where you can see what it's supposed to look like:
hidden link
Same deal, the search box and tag filters work, but not the category filter.

#143813

OK, so I just figured out why the category wasn't filtering. It needed to be "Value set by URL parameter".

Talking to myself here, but maybe it'll help someone else...

(I still need help with my original issue)

#144253

Dear Eric,

I will send you an email requesting access now. Let me know if you dont receive it to send it again.

Regards,
Caridad

#144482

Hi Caridad,

I created your user account a couple minutes after you emailed me. Let me know if you didn't receive the WordPress-generated email.

Thanks,
Eric

#144842

Dear Eric,

I received your access details. Can you point me to a search where this doesnt work? Give me some steps to follow so I can see the problem.

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

Regards,
Caridad

#144848

Sure, go here hidden link
Try the search box. Enter keywords such as "IT", "Database", etc. You'll see that the search box doesn't return results. The other inputs, do work however.

#144855

Dear Eric,

This is caused by some code in your theme:

// Get custom post types into WP native tag/category archives
	add_action( 'pre_get_posts', 'wpse_category_set_post_types' );
	
	function wpse_category_set_post_types( $query ){
		if( $query->is_tag || $query->is_category  || $query->is_search  ):
		$query->set( 'post_type', array( 'post', 'articles', 'case-studies' ) );
		endif;
		return $query;
	}

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

Regards,
Caridad

#144859

Yes, I wanted to assign a default category for each post type upon publishing the post, i.e.
Article custom post type gets Taxonomy > Categories > Article
Case Study custom post type gets Taxonomy > Categories > Case Study

That way I can use the Category filter checkboxes on the search page. If I could filter that search by custom post type (using checkboxes) that'd work, but I didn't see any options for that when building the view.

Is there something wrong with the code that assigns the categories?

#144864

...Sorry, I was thinking of this

// Assign categories to custom post types on "publish"  
	// Using this for parametric search
	// http://wordpress.org/support/topic/set-category-to-a-custom-post-type-automatically?replies=22
	function add_articles_category_automatically($post_ID) {
		global $wpdb;
		if(!has_term('','category',$post_ID)){
			$cat = array(158); // Articles category
			wp_set_object_terms($post_ID, $cat, 'category');
		}
	}
	add_action('publish_articles', 'add_articles_category_automatically');
	
	function add_case_studies_category_automatically($post_ID) {
		global $wpdb;
		if(!has_term('','category',$post_ID)){
			$cat = array(159); // Case Studies category
			wp_set_object_terms($post_ID, $cat, 'category');
		}
	}
	add_action('publish_case-studies', 'add_case_studies_category_automatically');

Those actions handle the auto-categorization...

Honestly, I can't remember why this block was necessary :

// Get custom post types into WP native tag/category archives
	add_action( 'pre_get_posts', 'wpse_category_set_post_types' );
	
	function wpse_category_set_post_types( $query ){
		if( $query->is_tag || $query->is_category  || $query->is_search  ):
		$query->set( 'post_type', array( 'post', 'articles', 'case-studies' ) );
		endif;
		return $query;
	}

I'm thinking there was a problem having types-generated post types use the native wordpress categories.

Not sure how to proceed, but appreciating your help very much. We have a launch Saturday and this is a key component.

Thanks,
Eric

#144868

Ugh. I'm seriously sleep-deprived and not helping myself (or you) here. The Articles and Case Study post types have nothing to do with this. Those are all working fine now.

This is strictly about the search box for the Jobs search. Can you let me know what might be wrong with that block of code you mentioned?

#144869

I think I'm getting closer. Just added 'jobs' to that block:

// Get custom post types into WP native tag/category archives
	add_action( 'pre_get_posts', 'wpse_category_set_post_types' );
	
	function wpse_category_set_post_types( $query ){
		if( $query->is_tag || $query->is_category  || $query->is_search  ):
		$query->set( 'post_type', array( 'post', 'articles', 'case-studies' ) );
		endif;
		return $query;
	}

Jobs searchbox is almost working. It's finding jobs now. But also finding other posts.

#144874

Hmmm. After making that change to the code, Jobs posts are being found in the Blog search (when using the search box): hidden link

Something I'm not filtering properly on these searches?

Jobs search should only find jobs. Blog search should only find articles and case studies.

#144896

Ah, I think I got it. Removed || $query->is_search from the function.

	add_action( 'pre_get_posts', 'wpse_category_set_post_types' );
	
	function wpse_category_set_post_types( $query ){
		if( $query->is_tag || $query->is_category  ):
		$query->set( 'post_type', array( 'post', 'articles', 'case-studies' ) );
		endif;
		return $query;
	}

Without that code, clicking on tag from a custom post type (Articles, Case Studies) displays an empty archive.

Thanks for pointing me in the right direction, Caridad. Sorry for the manic posts. 🙂