WordPress.org

Make WordPress Core

Opened 17 months ago

Last modified 17 months ago

#22540 new enhancement

Drilling categories for relevant posts via XML-RPC

Reported by: nidhi.patel Owned by:
Milestone: Awaiting Review Priority: normal
Severity: major Version: 3.4.2
Component: XML-RPC Keywords:
Focuses: Cc:

Description (last modified by scribu)

Hello WordPress,

Requirement for us was to drill down the category relevant posts, and I have implemented the solution using xmlrpc for the .net env using c#.

The trouble is there is no available option to filter using category for the posts.

So I have done following changes, please recommend if we can do any better to avoid the override of the change may be by upgrading the next version with it from WordPress version natively.

Describing the basic nitty-gritty with in :

After doing some cross referencing I was able to figure out adding following code shouldn't harm :

1: With in LLN#1374 function wp_getPosts( $args )
I added the filter option for category as follows on LN#1410

if ( isset( $filter['category'] ) )
    $query['category'] = $filter['category'];

I have done few tests and seems to be working fine, just its expects the categoryId to drill the category relevant posts for me.

I wonder if you could integrate this from WordPress.

2: Our second requirement was to get out of the box wpautop for the content, so we don't need to worry about adding <p><p/> tags.

hence the another change of code I had integrated with in the file is as following :

with in protected function _prepare_post( $post, $fields ) on LN#624 , I had added the wpautop call to surrounds to post_content as in follows :

'post_content'      => wpautop($post['post_content']),

Please guide or suggest how to avoid the override when upgrading the WordPress, one option is WordPress integrate these changes out of the box and until that we keep an eye and on ever upgrade keep doing the change.

Please feel free to reach me with any possible suggestions.

Regards,
Nidhi

Attachments (1)

class-wp-xmlrpc-server.php (148.1 KB) - added by nidhi.patel 17 months ago.
with updated patch to filter posts via category

Download all attachments as: .zip

Change History (14)

nidhi.patel17 months ago

with updated patch to filter posts via category

comment:1 scribu17 months ago

  • Description modified (diff)
  • Keywords 2nd-opinion needs-refresh removed
  • Summary changed from Requirement : Drilling category relevant posts to Drilling categories for relevant posts via XML-RPC

comment:2 follow-up: scribu17 months ago

  • Keywords has-patch dev-feedback needs-testing removed

Please try to submit a diff, not the full file. You can find tutorials here:

http://core.trac.wordpress.org/wiki#HowtoSubmitPatches

comment:3 markoheijnen17 months ago

I do know that your first thing isn't going to happen like that. It should support querying on taxonomy. I somehow thought we already implemented it in 3.4.

The second thing is a no for me. If you want you can still use the filter 'xmlrpc_prepare_post' to do so.

So the end of the story this ticket should be to have the possibility to query on taxonomies

comment:4 nidhi.patel17 months ago

@markoheijnen, thanks for the quick response:

Point# 1: I am using it and its working for me, definately it means, I have a ?caty="category_name" and which I utilize to do the search using getTaxonomy using XMLRPC and once I get the categoryid or taxonomy id, I utilize it to pass to getPosts for the category filter..

It allows me to grab the category relevant posts.

point# 2 : Please provide me with few details so if I use xmlrpc_prepare_post, as I am accessing everything in .net.

thanks,
Nidhi

comment:5 in reply to: ↑ 2 nidhi.patel17 months ago

Replying to scribu:

Please try to submit a diff, not the full file. You can find tutorials here:

http://core.trac.wordpress.org/wiki#HowtoSubmitPatches

thanks @scribu, I will study how I can upload the patch, and follow that.

comment:6 follow-up: markoheijnen17 months ago

Point 1: Yes it works but only for 1 taxonomy and not for custom ones. It should be a total solution.

Point 2:
This code makes it bulletproof for if the site is used by the mobile.
You do now need to send fifth parameter as: array( 'post', 'terms', 'custom_fields', 'autop' )

add_filter( 'xmlrpc_prepare_post', 'xmlrpc_prepare_post_autop' );

function xmlrpc_prepare_post_autop( $_post, $post, $fields ) {
	if( in_array( 'autop', $fields ) )
		$post['post_content'] = wpautop( $_post['post_content'] );

	return $_post;
}

ps: didn't test it

comment:7 in reply to: ↑ 6 nidhi.patel17 months ago

Replying to markoheijnen:

Point 1: Yes it works but only for 1 taxonomy and not for custom ones. It should be a total solution.

Point 2:
This code makes it bulletproof for if the site is used by the mobile.
You do now need to send fifth parameter as: array( 'post', 'terms', 'custom_fields', 'autop' )

add_filter( 'xmlrpc_prepare_post', 'xmlrpc_prepare_post_autop' );

function xmlrpc_prepare_post_autop( $_post, $post, $fields ) {
	if( in_array( 'autop', $fields ) )
		$post['post_content'] = wpautop( $_post['post_content'] );

	return $_post;
}

ps: didn't test it

Point#1 : Agreed , haven't provided for multiple category, as it only expects the integer, if a string "," separated than it could resolve it.

I think eventually that should be the optimal solution, currently what I provided only drills for single id, it depends how custom category are stored, if they utilize the same field , can make that work, just how the access point is defined need more logic, which again depends on the usage.

Point#2: This mean you suggesting to add with in the same xmlrpc file?

Regards,
Nidhi

comment:8 follow-up: markoheijnen17 months ago

When using WordPress you should do a little more research. A category is a taxonomy just like tags. But you can also write custom ones for custom post type like posts or pages.

You can write your own plugins and the code I passed is code that should go in your own plugin ( or theme )

Rest of the specific question should be asked on the support forums

Last edited 17 months ago by markoheijnen (previous) (diff)

comment:9 in reply to: ↑ 8 nidhi.patel17 months ago

Replying to markoheijnen:

When using WordPress you should do a little more research. A category is a taxonomy just like tags. But you can also write custom ones for custom post type like posts or pages.

You can write your own plugins and the code I passed is code that should go in your own plugin ( or theme )

Rest of the specific question should be asked on the support forums

Surely enough, I am aware about category, taxonomy and custom ones, if that makes sense... If you read through what I meant covers that part.

thanks,
Nidhi

comment:10 follow-up: markoheijnen17 months ago

I explained because I got worried that you still wanted to change core code. Something you never should do ;)

comment:11 in reply to: ↑ 10 nidhi.patel17 months ago

Replying to markoheijnen:

I explained because I got worried that you still wanted to change core code. Something you never should do ;)

much appreciated the concern, hence opening a ticket or gathering suggestions, as for sure we have the need , not sure if someone else is facing the need, and how to get it be going out of the box.

thanks for suggestions and concerns, keep it coming, so can figure out the best approach.

thanks,
Nidhi

comment:12 nidhi.patel17 months ago

Okay as per @scribu's suggestion I tried to commit to svn but I get following error :

Command: Commit
Error: Commit failed (details follow):
Error: Access to '/!svn/act/af4854ef-16eb-6543-ab7c-c34795ab9bac' forbidden
Completed!:

Am I missing anything?

Regards!

comment:13 scribu17 months ago

You're not supposed to commit. Just generate a diff and upload it here.

Note: See TracTickets for help on using tickets.