{"id":4191,"date":"2021-02-20T10:15:27","date_gmt":"2021-02-20T15:15:27","guid":{"rendered":"https:\/\/themespress.ca\/?p=4191"},"modified":"2021-07-07T06:20:50","modified_gmt":"2021-07-07T10:20:50","slug":"query-wordpress-multisite-network","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/query-wordpress-multisite-network\/","title":{"rendered":"Create a Query With a WordPress Multisite Network"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><div class=\"vc_row wpb_row vc_row-fluid\"><div class=\"wpb_column vc_column_container vc_col-sm-12\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>In this tutorial we will show how to create a query that will pull a specific website&#8217;s post type within the multisite network. <\/p>\n<p>In order to attain this, we will use the <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/switch_to_blog\/\" target=\"_blank\" rel=\"noopener\"><strong>switch_to_blog();<\/strong><\/a> function and find the blog ID that matches the website&#8217;s ID where we want to pull the post type data from. <\/p>\n<p>Dans notre exemple ci-dessous, nous allons renvoyer nos r\u00e9sultats dans un shortcode du nom de [listeentreprises]. <strong>Ce shortcode affichera les r\u00e9sultats par exemple dans une page d\u2019un autre site web du multisite.<\/strong> In the example below, we will generate our results with a shortcode titled [listeentreprises]. <strong>This shortcode will display the results on a page of another website from the multisite network.<\/strong> <\/p>\n<p>We need to create our <strong>switch_to_blog(3)<\/strong> and close it with <strong><a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/restore_current_blog\/\" target=\"_blank\" rel=\"noopener\">restore_current_blog<\/a><\/strong> which will create the multisite query. The ID 3 is our website&#8217;s ID. <\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-6658032\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-6658032\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"php\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ Shortcode Afficher entreprises \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\nadd_shortcode(&#039;listeentreprises&#039;, &#039;themespress_afficher_entreprise&#039;);\nfunction themespress_afficher_entreprise() {\n    \/\/ Requete de l&#039;ID de notre site web\n    switch_to_blog(3);\n\n    \/\/ pr&eacute;parer la query pour r&eacute;cup&eacute;rer le post type &agrave; afficher\n    $args = array(\n        &#039;post_type&#039; =&gt; &#039;votreposttype&#039;,\n\t&#039;posts_per_page&#039; =&gt; -1,\n\t&#039;order&#039; =&gt; &#039;ASC&#039;,\n        &#039;orderby&#039; =&gt; &#039;title&#039;,\n    );\n    $the_query = new WP_Query( $args );\n\n    echo&#039;&lt;ul&gt;&#039;;\n\t\n\t  while ( $the_query-&gt;have_posts() ) { $the_query-&gt;the_post();\n\t\techo &#039;&lt;li&gt;&#039; . get_the_title() . &#039;&lt;\/li&gt;&#039;;\n         }\n    echo&#039;&lt;\/ul&gt;&#039;;\n\n    \/\/ revenir &agrave; Local d&rsquo;abord\n    restore_current_blog();\n    return $entreprise;\n}<\/pre><\/div><h2 style=\"text-align: left\" class=\"vc_custom_heading vc_do_custom_heading\" >Afficher une vue formidable form dans un multisite WordPress<\/h2>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p> We have now created our results which included entreprise Post Type.<\/p>\n<p>Following the same logic, we will create a shortcode and a <strong>return shortcode with Vue <a href=\"https:\/\/shareasale.com\/r.cfm?b=841990&amp;u=1476870&amp;m=64739&amp;urllink=&amp;afftrack=0\" target=\"_blank\" rel=\"noopener\">Formidable Form<\/a>.<\/strong><\/p>\n<p>Our shortcode in the example below will be [vuespost]. <strong>This shortcode will display the results in a page of another website within the multisite network<\/strong><\/p>\n<p>Replace it by yours.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-7625179\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-7625179\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"php\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ Afficher vue formidable form  \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\nadd_shortcode(&#039;vuespost&#039;, &#039;themespress_vuesPOST_shortcode&#039;);\nfunction themespress_vuesPOST_shortcode(){\n\t\/\/ Requete de l&#039;ID de notre site web\n        switch_to_blog(3);\n\t$output = do_shortcode(&#039;[display-frm-data id=25033]&#039;);\n\trestore_current_blog();\n\treturn $output;\n}<\/pre><\/div><div class=\"vc_empty_space\"   style=\"height: 20px\"><span class=\"vc_empty_space_inner\"><\/span><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p><strong>NB : Make sure to do a backup of your theme and dabatase before using these functions.<\/strong><\/p>\n\n\t\t<\/div>\n\t<\/div>\n<\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"In this tutorial we will show how to create a query that will pull a specific website's post type within the multisite network. In order to attain this, we will<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/query-wordpress-multisite-network\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":4026,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[],"class_list":["post-4191","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/4191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/users\/81"}],"replies":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/comments?post=4191"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/4191\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/4026"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=4191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=4191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=4191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}