[wp-xmlrpc] Post ID from Custom Fields

Pickling Jar Coders code at thepicklingjar.com
Sun Jul 12 02:17:25 UTC 2009


In case the patch was mangled by my mail client, it can be found on
trac http://core.trac.wordpress.org/ticket/10388

Thanks

2009/7/12 Pickling Jar Coders <code at thepicklingjar.com>:
> Evening List,
>
> Below is a patch that returns post/page id's via a custom field key
> value pair lookup. The idea being that when one is using wordpress as
> a cms, one sometimes needs to find a specific post via a custom field
> value. Without the patch, one would have to query the DB directly. The
> patch is for 2.8.1
>
> Thanks
> Pickling Jar Coders
>
>
> --- xmlrpc.php.old      Sun Jul 12 01:26:27 2009
> +++ xmlrpc.php  Sun Jul 12 01:29:38 2009
> @@ -154,6 +154,7 @@
>                        'wp.editComment'                =>
> 'this:wp_editComment',
>                        'wp.newComment'                 => 'this:wp_newComment',
>                        'wp.getCommentStatusList' =>
> 'this:wp_getCommentStatusList',
> +                       'wp.getPostIdFromCustomFields'  =>
> 'this:wp_getPostIdFromCustomFields',
>
>                        // Blogger API
>                        'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs',
> @@ -1566,6 +1567,42 @@
>                //Now return the updated values
>                return $this->_getOptions($option_names);
>        }
> +
> +        /**
> +         *
> +         * Search for a post id with a custom field name and value
> +         *
> +         * @since 2.9.0
> +         *
> +         * @param array $args Methods parameters.
> +         * @return array
> +         */
> +        function wp_getPostIdFromCustomFields($args){
> +                global $wpdb;
> +                $this->escape( $args );
> +
> +                $blog_id        = (int) $args[0];
> +                $username       = $args[1];
> +                $password       = $args[2];
> +                $fieldname      = $args[3];
> +                $fieldvalue     = $args[4];
> +
> +                if ( !$user = $this->login($username, $password) ) {
> +                        return $this->error;
> +                }
> +
> +                if( !current_user_can( 'read_private_posts' ) )
> +                        return new IXR_Error( 403, __( 'You are not
> allowed search custom fields on this blog.' ) );
> +
> +                $postids = $wpdb->get_results( $wpdb->prepare("SELECT
> post_id FROM {$wpdb->postmeta} WHERE meta_key = %s AND meta_value =
> %s", $fieldname, $fieldvalue) );
> +                if (!$postids) {
> +                        return array();
> +                }
> +                else {
> +                        return($postids);
> +                }
> +        }
> +
>
>        /* Blogger API functions.
>         * specs on http://plant.blogger.com/api and
> http://groups.yahoo.com/group/bloggerDev/
>
>
>
>
>
>
> tel: +44 (0)844 736 1563
> email: code at thepicklingjar.com
> web: http://www.thepicklingjar.com/
>
> This email and any attachments to it may be confidential and are
> intended solely for the use of the individual to whom it is addressed.
> Any views or opinions expressed are only possibly those of the author
> and certainly do not represent those of The Pickling Jar Limited.
>
> The Pickling Jar Limited
> Company number 6489739 (England & Wales) VAT GB938944665
> Registered office: 19 Moulton Park Office Village, Northampton, NN3 6AP
>


More information about the wp-xmlrpc mailing list