{"id":47281,"date":"2019-11-06T15:00:39","date_gmt":"2019-11-06T09:30:39","guid":{"rendered":"https:\/\/git-staging.wpastra.com\/?post_type=docs&#038;p=47281"},"modified":"2024-02-06T19:05:21","modified_gmt":"2024-02-06T13:35:21","slug":"restrict-search-results-post","status":"publish","type":"docs","link":"https:\/\/git-staging.wpastra.com\/es\/docs\/restrict-search-results-post\/","title":{"rendered":"Restringir los resultados de la b\u00fasqueda s\u00f3lo a los mensajes"},"content":{"rendered":"<p>Astra proporciona un <a href=\"https:\/\/git-staging.wpastra.com\/es\/docs\/restrict-search-results-post\/\">opci\u00f3n de b\u00fasqueda dentro de un sitio web junto con algunos estilos<\/a>. <\/p>\n\n\n\n<p>Cuando un usuario busca cualquier t\u00e9rmino (cadena), los resultados se sirven de todo el sitio web, incluyendo todas tus p\u00e1ginas y entradas. Aunque no existe una opci\u00f3n para restringir la b\u00fasqueda solo a las entradas, puedes hacerlo con un c\u00f3digo personalizado.<\/p>\n\n\n\n<p>Este documento le mostrar\u00e1 c\u00f3mo restringir la b\u00fasqueda s\u00f3lo a las entradas. Adem\u00e1s, tambi\u00e9n encontrar\u00e1s c\u00f3digo adicional para excluir los productos de WooCommerce si tienes una tienda online. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Restringir la b\u00fasqueda a los mensajes<\/h2>\n\n\n\n<p>Para limitar tu b\u00fasqueda s\u00f3lo a las entradas, ve a Panel &gt; Apariencia &gt; Editor de temas. Aqu\u00ed, tendr\u00e1s que a\u00f1adir el siguiente c\u00f3digo personalizado a tu Astra Child Theme <a style=\"font-size: 1rem;\" href=\"https:\/\/git-staging.wpastra.com\/es\/docs\/add-custom-php-code\/#3.-in-child-theme\">funciones.php<\/a> <span style=\"font-size: 1rem;\">archivo<\/span>:<\/p>\n\n\n\n<pre class=\"wp-block-code\" data-no-translation=\"\" data-no-auto-translation=\"\"><code>add_action( 'wp', 'astra_modify_search_loop', 99 );\n\n\/**\n* Modify Search Loop.\n*\n* @return void\n*\/\nfunction astra_modify_search_loop() {\n    remove_action( 'astra_content_loop', array( Astra_Loop::get_instance(), 'loop_markup' ) );\n    add_action( 'astra_content_loop', 'astra_redo_loop_markup' );\n}\n\n\/**\n* Redo loop to search only posts.\n*\n* @return void\n*\/\nfunction astra_redo_loop_markup( $is_page = false ) {\n\n    global $post;\n\n    ?>\n    &lt;main id=\"main\" class=\"site-main\" role=\"main\">\n\n        &lt;?php if ( have_posts() ) : ?>\n\n            &lt;?php do_action( 'astra_template_parts_content_top' ); ?>\n\n            &lt;?php\n            while ( have_posts() ) :\n                the_post();\n\n<strong>                if ( is_search() &amp;&amp; ( 'page' == $post->post_type ) ) {\n                    continue;\n                }<\/strong>\n\n                if ( true == $is_page ) {\n                    do_action( 'astra_page_template_parts_content' );\n                } else {\n                    do_action( 'astra_template_parts_content' );\n                }\n\n                ?>\n\n            &lt;?php endwhile; ?>\n\n            &lt;?php do_action( 'astra_template_parts_content_bottom' ); ?>\n\n        &lt;?php else : ?>\n\n            &lt;?php do_action( 'astra_template_parts_content_none' ); ?>\n\n        &lt;?php endif; ?>\n\n    &lt;\/main>&lt;!-- #main -->\n    &lt;?php\n}\n\nfunction astra_exclude_products_from_search( $query ) {\n\u00a0\u00a0\u00a0\u00a0if ( ! is_admin() &amp;&amp; $query->is_search() ) {\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$query->set( 'post_type', 'post' );\n\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0}\u00a0\u00a0<\/code><\/pre>\n\n\n\n<p> Si no tiene instalado el tema infantil, compruebe lo siguiente <a href=\"https:\/\/git-staging.wpastra.com\/es\/docs\/install-astra-child-theme\/\">este art\u00edculo<\/a> sobre c\u00f3mo hacerlo.  Adem\u00e1s, si usted no est\u00e1 seguro de c\u00f3mo agregar este c\u00f3digo, por favor revise esto <a href=\"https:\/\/git-staging.wpastra.com\/es\/docs\/add-custom-php-code\/#3.-in-child-theme\">art\u00edculo<\/a>. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Uso del c\u00f3digo con Woocommerce<\/h2>\n\n\n\n<p>Adem\u00e1s, si tienes WooCommerce funcionando en tu web, tus productos se seguir\u00e1n mostrando junto a las entradas. <\/p>\n\n\n\n<p>Por lo tanto, para excluir tambi\u00e9n los productos de WooCommerce de la b\u00fasqueda, necesitar\u00e1 una versi\u00f3n modificada del c\u00f3digo mencionado anteriormente. <\/p>\n\n\n\n<p>Por lo tanto, tendr\u00e1 que sustituir esta parte en negrita del c\u00f3digo:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">if ( is_search() &amp;&amp; ( 'page' == $post-&gt;post_type ) ) {\n   continuar;\n}<\/pre>\n\n\n\n<p>...con \u00e9ste:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">if ( is_search() &amp;&amp; ( 'page' == $post-&gt;post_type || 'product' == $post-&gt;post_type ) ) {\n   continuar;\n}\n<\/pre>\n\n\n\n<p>Si modificas el c\u00f3digo de esta forma, tanto las p\u00e1ginas como los productos de WooCommerce se omitir\u00e1n de la b\u00fasqueda. En consecuencia, solo se mostrar\u00e1n las entradas como resultado de la b\u00fasqueda.<\/p>\n\n\n\n<p>Ya est\u00e1. Esperamos que esta gu\u00eda te haya ayudado.<\/p>\n\n\n\n<p>Si tiene alg\u00fan problema durante el proceso, no dude en ponerse en contacto con nuestro equipo de asistencia. Siempre estamos aqu\u00ed para ayudarte.<\/p>","protected":false},"excerpt":{"rendered":"<p>Astra proporciona una opci\u00f3n de b\u00fasqueda dentro de un sitio web junto con algunos estilos. Cuando un usuario busca cualquier t\u00e9rmino (cadena), los resultados son servidos desde todo el sitio web, incluyendo todas tus p\u00e1ginas y entradas. Aunque no existe una opci\u00f3n para restringir la b\u00fasqueda s\u00f3lo a las entradas, puedes hacerlo con un c\u00f3digo personalizado. [...]<\/p>","protected":false},"author":20,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"default","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"docs_category":[2109],"docs_tag":[],"class_list":{"0":"post-47281","1":"docs","2":"type-docs","3":"status-publish","5":"docs_category-astra-theme-pro-filters"},"spectra_custom_meta":{"_edit_lock":["1707226638:109"],"_edit_last":["109"],"onesignal_meta_box_present":["1"],"onesignal_send_notification":[""],"tap_disable_autolinker":["no"],"tap_autolink_inside_heading":["global"],"tap_autolink_random_placement":["global"],"tap_post_autolinker_limit":["0"],"site-sidebar-layout":["default"],"site-content-layout":["default"],"theme-transparent-header-meta":["default"],"_yoast_wpseo_content_score":["90"],"_ppc_meta_key":["a:8:{s:20:\"ppc_key5d92f85d42273\";s:60:\"Images &amp; Names Correctly. Title &amp; Alt Tags are Given\";s:8:\"ppc_key4\";s:15:\"Formatting Done\";s:8:\"ppc_key2\";s:23:\"Featured Image Assigned\";s:8:\"ppc_key3\";s:17:\"Category Selected\";s:8:\"ppc_key5\";s:15:\"Title is Catchy\";s:8:\"ppc_key6\";s:22:\"Social Images Assigned\";s:8:\"ppc_key7\";s:8:\"Done SEO\";s:8:\"ppc_key8\";s:28:\"Spelling and Grammar Checked\";}"],"_elementor_controls_usage":["a:0:{}"],"_ht_kb_post_views_count":["9"],"_ht_kb_usefulness":["0"],"_ht_article_order_103":["47281"],"wp_last_modified_info":["August 22, 2022 @ 1:47 PM"],"wplmi_shortcode":["[lmt-post-modified-info]"],"views":["5933"],"helpful":["2"],"unhelpful":["1"],"redirects":["9"],"_yoast_wpseo_estimated-reading-time-minutes":["2"],"_lmt_disableupdate":["no"],"_wplmi_last_modified":["2022-08-22 13:47:32"],"_yoast_wpseo_primary_docs_category":["2109"],"_yoast_wpseo_focuskw":["Restrict Search to Posts"],"_yoast_wpseo_metadesc":["Learn how to restrict the search to posts only on Astra website. In addition, you can also exclude WooCommerce products, if you're running an online store."],"_yoast_wpseo_linkdex":["67"],"rank_math_primary_docs_category":["2109"],"rank_math_description":["Learn how to restrict the search to posts only on Astra website. In addition, you can also exclude WooCommerce products, if you're running an online store."],"rank_math_focus_keyword":["Restrict Search to Posts"],"rank_math_news_sitemap_robots":["index"],"rank_math_robots":["a:1:{i:0;s:5:\"index\";}"],"rank_math_analytic_object_id":["779"],"rank_math_internal_links_processed":["1"],"rank_math_seo_score":["15"],"_trp_automatically_translated_slug_es_ES":["restringir-los-resultados-de-busqueda-post"],"_uag_custom_page_level_css":[""],"ast-site-content-layout":["default"],"adv-header-id-meta":[""],"stick-header-meta":[""],"astra-migrate-meta-layouts":["set"],"pfd_related_docs":[""],"_uag_page_assets":["a:9:{s:3:\"css\";s:2495:\".wp-block-uagb-container.uagb-block-debf2792 .uagb-container__shape-top svg{width: calc( 100% + 1.3px );}.wp-block-uagb-container.uagb-block-debf2792 .uagb-container__shape.uagb-container__shape-top .uagb-container__shape-fill{fill: rgba(51,51,51,1);}.wp-block-uagb-container.uagb-block-debf2792 .uagb-container__shape-bottom svg{width: calc( 100% + 1.3px );}.wp-block-uagb-container.uagb-block-debf2792 .uagb-container__shape.uagb-container__shape-bottom .uagb-container__shape-fill{fill: rgba(51,51,51,1);}.wp-block-uagb-container.uagb-block-debf2792 .uagb-container__video-wrap video{opacity: 1;}.wp-block-uagb-container.uagb-is-root-container .uagb-block-debf2792{max-width: 100%;width: 100%;}.wp-block-uagb-container.uagb-is-root-container.alignfull.uagb-block-debf2792 > .uagb-container-inner-blocks-wrap{--inner-content-custom-width: min( 100%, 1200px);max-width: var(--inner-content-custom-width);width: 100%;flex-direction: column;align-items: center;justify-content: center;flex-wrap: nowrap;row-gap: 0px;column-gap: 0px;}.wp-block-uagb-container.uagb-block-debf2792{box-shadow: 0px 0px   #00000070 ;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;margin-top: 0px !important;margin-bottom: 0px !important;margin-left: 0px;margin-right: 0px;overflow: visible;border-color: inherit;row-gap: 0px;column-gap: 0px;}@media only screen and (max-width: 976px) {.wp-block-uagb-container.uagb-is-root-container .uagb-block-debf2792{width: 100%;}.wp-block-uagb-container.uagb-is-root-container.alignfull.uagb-block-debf2792 > .uagb-container-inner-blocks-wrap{--inner-content-custom-width: min( 100%, 1024px);max-width: var(--inner-content-custom-width);width: 100%;}.wp-block-uagb-container.uagb-block-debf2792{padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;margin-top: 0px !important;margin-bottom: 0px !important;margin-left: 0px;margin-right: 0px;}}@media only screen and (max-width: 767px) {.wp-block-uagb-container.uagb-is-root-container .uagb-block-debf2792{max-width: 100%;width: 100%;}.wp-block-uagb-container.uagb-is-root-container.alignfull.uagb-block-debf2792 > .uagb-container-inner-blocks-wrap{--inner-content-custom-width: min( 100%, 767px);max-width: var(--inner-content-custom-width);width: 100%;flex-wrap: wrap;}.wp-block-uagb-container.uagb-block-debf2792{padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;margin-top: 0px !important;margin-bottom: 0px !important;margin-left: 0px;margin-right: 0px;}}\";s:2:\"js\";s:0:\"\";s:18:\"current_block_list\";a:6:{i:0;s:14:\"core\/paragraph\";i:1;s:12:\"core\/heading\";i:2;s:9:\"core\/code\";i:3;s:17:\"core\/preformatted\";i:4;s:14:\"uagb\/container\";i:5;s:14:\"core\/shortcode\";}s:8:\"uag_flag\";b:1;s:11:\"uag_version\";s:10:\"1776682129\";s:6:\"gfonts\";a:0:{}s:10:\"gfonts_url\";s:0:\"\";s:12:\"gfonts_files\";a:0:{}s:14:\"uag_faq_layout\";b:0;}"]},"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"trp-custom-language-flag":false},"uagb_author_info":{"display_name":"Anjali","author_link":"https:\/\/git-staging.wpastra.com\/es\/author\/anjalic\/"},"uagb_comment_info":0,"uagb_excerpt":"Astra provides a search option within a website along with a few styles. When a user searches for any term (string), results are served from the entire website, including all your pages and posts. Though there is no out-of-the-box option to restrict the search to posts only, you can do it with a custom code.&hellip;","_links":{"self":[{"href":"https:\/\/git-staging.wpastra.com\/es\/wp-json\/wp\/v2\/docs\/47281"}],"collection":[{"href":"https:\/\/git-staging.wpastra.com\/es\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/git-staging.wpastra.com\/es\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/git-staging.wpastra.com\/es\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/git-staging.wpastra.com\/es\/wp-json\/wp\/v2\/comments?post=47281"}],"version-history":[{"count":0,"href":"https:\/\/git-staging.wpastra.com\/es\/wp-json\/wp\/v2\/docs\/47281\/revisions"}],"wp:attachment":[{"href":"https:\/\/git-staging.wpastra.com\/es\/wp-json\/wp\/v2\/media?parent=47281"}],"wp:term":[{"taxonomy":"docs_category","embeddable":true,"href":"https:\/\/git-staging.wpastra.com\/es\/wp-json\/wp\/v2\/docs_category?post=47281"},{"taxonomy":"docs_tag","embeddable":true,"href":"https:\/\/git-staging.wpastra.com\/es\/wp-json\/wp\/v2\/docs_tag?post=47281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}