{"id":110158,"date":"2019-10-05T18:45:37","date_gmt":"2019-10-05T18:45:37","guid":{"rendered":"https:\/\/wordpress.org\/plugins\/arha-routes\/"},"modified":"2020-05-15T06:18:46","modified_gmt":"2020-05-15T06:18:46","slug":"arha-routes","status":"publish","type":"plugin","link":"https:\/\/bal.wordpress.org\/plugins\/arha-routes\/","author":17460990,"comment_status":"closed","ping_status":"closed","template":"","meta":{"version":"1.5","stable_tag":"trunk","tested":"5.3.21","requires":"5.0","requires_php":"7.1","requires_plugins":"","header_name":"Arha Routes","header_author":"Atte Liimatainen","header_description":"Adds REST endpoints for Headless setup","assets_banners_color":"","last_updated":"2020-05-15 06:18:46","external_support_url":"","external_repository_url":"","donate_link":"","header_plugin_uri":"","header_author_uri":"","rating":0,"author_block_rating":0,"active_installs":10,"downloads":1514,"num_ratings":0,"support_threads":0,"support_threads_resolved":0,"author_block_count":0,"sections":["description"],"tags":[],"upgrade_notice":[],"ratings":[],"assets_icons":[],"assets_banners":[],"assets_blueprints":{},"all_blocks":[],"tagged_versions":[],"block_files":[],"assets_screenshots":[],"screenshots":[]},"plugin_section":[],"plugin_tags":[6370,8713,1385,99,2299],"plugin_category":[48],"plugin_contributors":[177030],"plugin_business_model":[],"class_list":["post-110158","plugin","type-plugin","status-publish","hentry","plugin_tags-bilingual","plugin_tags-endpoint","plugin_tags-language","plugin_tags-multilingual","plugin_tags-rest","plugin_category-language-tools","plugin_contributors-attlii","plugin_committers-attlii"],"banners":[],"icons":{"svg":false,"icon":"https:\/\/s.w.org\/plugins\/geopattern-icon\/arha-routes.svg","icon_2x":false,"generated":true},"screenshots":[],"raw_content":"<!--section=description-->\n<p>Wordpress plugin that helps to serve content through REST routes and gives\ncustomizability to developers through filters.<\/p>\n\n<h3>Available Routes<\/h3>\n\n<ul>\n<li><code>\/wp-json\/arha\/v1\/post<\/code><\/li>\n<li><code>\/wp-json\/arha\/v1\/page<\/code><\/li>\n<li><code>\/wp-json\/arha\/v1\/options<\/code><\/li>\n<li><code>\/wp-json\/arha\/v1\/archive<\/code><\/li>\n<\/ul>\n\n<h3>Example queries<\/h3>\n\n<ul>\n<li><code>\/wp-json\/arha\/v1\/post?post_type=POST_TYPE&amp;slug=SLUG<\/code><\/li>\n<li><code>\/wp-json\/arha\/v1\/page?path=PATH<\/code><\/li>\n<li><code>\/wp-json\/arha\/v1\/options<\/code><\/li>\n<li><code>\/wp-json\/arha\/v1\/archive?post_type=POST_TYPE&amp;posts_per_page=POSTS_PER_PAGE&amp;paged=PAGED&amp;orderby=ORDERBY&amp;order=ORDER<\/code><\/li>\n<\/ul>\n\n<h3>tax_query and meta_query in archive-route<\/h3>\n\n<ul>\n<li><code>tax_query<\/code> and <code>meta_query<\/code> are supported and they work how the query is built for it in <code>new WP_Query()<\/code><\/li>\n<li>both needs their values to bes passed in as stringified json<\/li>\n<\/ul>\n\n<h3>Multiple post_types in archive-route<\/h3>\n\n<ul>\n<li>To pass multiple post_types in archive-route, use syntax that lets PHP read GET-param as an array. https:\/\/stackoverflow.com\/a\/9547490<\/li>\n<\/ul>\n\n<h3>Filters<\/h3>\n\n<ul>\n<li><p>To exclude querying specific post types from <code>post<\/code>- and <code>archive<\/code>-routes, you\ncan use following filters:<\/p>\n\n<p>`\nadd_filter('arha_routes\/archive_excluded_post_types', 'exclude_post_types');\nadd_filter('arha_routes\/post_excluded_post_types', 'exclude_post_types');<\/p><\/li>\n<\/ul>\n\n<p>function exclude_post_types($excluded_post_types) {\n  $excluded_post_types = ['post'];\n  return $excluded_post_types;\n}\n    `<\/p>\n\n<ul>\n<li>To format <code>post<\/code>-route's post before it's served to client, use <code>arha_routes\/format_post<\/code>-filter\n`\nadd_filter('arha_routes\/format_post', 'format_post');<\/li>\n<\/ul>\n\n<p>function format_post($post) {\n  return $post;\n}\n    `<\/p>\n\n<ul>\n<li>To format <code>page<\/code>-route's post before it's served to client, use <code>arha_routes\/format_page<\/code>-filter\n`\nadd_filter('arha_routes\/format_page', 'format_page');<\/li>\n<\/ul>\n\n<p>function format_page($page) {\n  return $page;\n}\n    `<\/p>\n\n<ul>\n<li><p>To format <code>archive<\/code>-route's posts before they are served to client, use <code>arha_routes\/format_archive_post<\/code>-filter<\/p>\n\n<p><code>add_filter('arha_routes\/format_archive_post', 'format_archive_post');\nfunction format_archive_post($post) {\nreturn $post;\n}<\/code><\/p><\/li>\n<li><p><code>options<\/code>-route returns empty result by default. To add content to it, use <code>arha_routes\/format_options<\/code>-filter\n`\nadd_filter('arha_routes\/format_options', 'format_options');<\/p><\/li>\n<\/ul>\n\n<p>function format_options($options) {\n  return $options;\n}\n    `<\/p>\n\n<ul>\n<li><p>By default Arha Routes returns only published content with post-, page- and archive-route, this can be modified by adding following filters.\n`\n\/\/ for archive route\nadd_filter('arha_routes\/allowed_post_statuses_archive', 'allowed_post_statuses');\n\/\/ for post route\nadd_filter('arha_routes\/allowed_post_statuses_post', 'allowed_post_statuses');\n\/\/ for page route\nadd_filter('arha_routes\/allowed_post_statuses_page', 'allowed_post_statuses');\nfunction allowed_post_statuses($post_statuses) {\n\/\/ ... change post_statuses array<\/p>\n\n<p>return $post_statuses;\n}\n`\nAfter adding setting up these filters, request can include \"post_status\" parameter and it will be compared to $post_statuses array.<\/p><\/li>\n<\/ul>\n\n<h3>SearchWP<\/h3>\n\n<p>Arha Routes supports SearchWP-plugin, which lets WP users to make keyword search engine for their content.<\/p>\n\n<p>Activating SearchWP-plugin adds optional keyword-search functionality to <code>archive<\/code>-route. This is done by adding <code>s=KEYWORD<\/code> to the route\n- Example: <code>\/wp-json\/arha\/v1\/archive?post_type=products&amp;posts_per_page=10&amp;paged=1&amp;orderby=date&amp;order=ASC&amp;s=monitor<\/code><\/p>\n\n<h3>Polylang<\/h3>\n\n<p>Arha Routes supports Polylang-plugin, which allows users to create content in multiple languages.<\/p>\n\n<p>Activating Polylang changes how endpoints work:<\/p>\n\n<ul>\n<li>All routes require additional <code>lang<\/code>-param\n\n<ul>\n<li>Example: <code>\/wp-json\/arha\/v1\/archive?post_type=products&amp;posts_per_page=10&amp;paged=1&amp;orderby=date&amp;order=ASC&amp;lang=en<\/code><\/li>\n<\/ul><\/li>\n<li><code>page<\/code>-route doesn't support language prefix in path\n\n<ul>\n<li>Example: Permalink <code>\/zh\/info<\/code>, use like this <code>\/wp-json\/arha\/v1\/page?path=\/info&amp;lang=zh<\/code><\/li>\n<li>Example: Permalink <code>\/en\/info\/test<\/code>, use like this <code>\/wp-json\/arha\/v1\/page?path=\/info\/test&amp;lang=zh<\/code><\/li>\n<\/ul><\/li>\n<li><code>options<\/code>-route passes <code>lang<\/code>-param forward to <code>arha_routes\/format_options<\/code>-filter\n<code>add_filter('arha_routes\/format_options', 'format_options', 10, 2);\nfunction format_options($options, $lang) {\nreturn $options;\n}<\/code><\/li>\n<\/ul>\n\n<h3>Polylang + SearchWP<\/h3>\n\n<p>In order to make these two plugins work together, you need to add extra plugin to WP installation.<\/p>\n\n<p>https:\/\/searchwp.com\/extensions\/polylang-integration\/<\/p>","raw_excerpt":"Wordpress plugin that helps to serve content through REST routes and gives customizability to developers through filters.","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/bal.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/110158","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bal.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/bal.wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"replies":[{"embeddable":true,"href":"https:\/\/bal.wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=110158"}],"author":[{"embeddable":true,"href":"https:\/\/bal.wordpress.org\/plugins\/wp-json\/wporg\/v1\/users\/attlii"}],"wp:attachment":[{"href":"https:\/\/bal.wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=110158"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/bal.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=110158"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/bal.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=110158"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/bal.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=110158"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/bal.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=110158"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/bal.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=110158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}