• Guys, i need to do a select all blogs in the network of may main blog of network, something like this way:

    $sql = "SELECT DISTINCT
    	retorno.meta_value
    	FROM
     ".$wpdb->posts."
    	LEFT JOIN ".$wpdb->postmeta." AS requisicao ON requisicao.post_id = ".$wpdb->posts.".ID
    	LEFT JOIN ".$wpdb->postmeta." AS retorno ON retorno.post_id = requisicao.post_id
    WHERE....

    The question is, how to do it FROM “.$wpdb->posts.” or “.$wpdb->postmeta.” be the wp_postmeta and wp_posts of all blogs on the network?

    Do not quite understand, but SELECT something like SELECT DISTINCT FROM wp_2_posts AND wp_3_posts AND wp_4_posts AND … infinitely

    Is this possible?

Viewing 4 replies - 1 through 4 (of 4 total)
  • “…infinitely…”? Sure, with a loop. Have a look at some old code in ah_recent_posts_mu.

    I wouldn’t do it on a site with a pile’o’blogs. Recent versions of WP added a new function wp_get_sites, but I haven’t paid attention to how it is being used in templates or plugins around here.

    What I would do, instead of going out to get all posts, is use a plugin that collects all the posts in one site first.

    http://wordpress.org/plugins/wordpress-mu-sitewide-tags/

    Donncha’s plugin will create a site to aggregate all posts into one site in your network. Then the usual WordPress template functions can be used to fetch post data.

    With the plugin set up you can very quickly create something like

    http://en.wordpress.com/tags/

    and

    http://en.wordpress.com/fresh/

    Thread Starter Anderson Narciso

    (@andersonnarciso)

    @david Sader thanks for reply!

    When i say infinitely is that at any moment can be added a new blog to the network, then the select (a searcher) would have to look for this new blog too, my select has to be made entirely in the hand, as it is a select to search buildings, a network of real estate websites

    So i just need to know what to put in the place of $wpdb-> postmeta or $wpdb-> posts that did he select in all wp_prefix_posts and wp_prefix_postmeta

    I’ve got a select to do something like http://en.wordpress.com/fresh/ via this link http://www.bappi-d-great.com/wordpress-multisite-how-to-show-popular-post-acrosee-the-network-without-any-plugin

    But this other i’m trying to assemble not only search posts, search custom fields in custom post types in sequence of combobox

    Select Negotiation
    Select type of property
    Select State
    Select City
    Select Neighborhood

    In all the network sites. So I needed to know what to use in place of this select

    $sql = “SELECT DISTINCT retorno.meta_value FROM “.$wpdb->posts.”

    FROM??? In all the blogs on the network..

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    It helps when you tell us WHY 🙂

    So you want to search all sites?

    http://wordpress.org/extend/plugins/multisite-global-search/

    And there are others as well.

    http://wordpress.org/extend/plugins/search.php?q=multisite+search

    I would use that plugin and, if it’s not getting everything, fork it, rather than start from scratch.

    Thread Starter Anderson Narciso

    (@andersonnarciso)

    I am extremely grateful for the replies, and my apologize for my bad English understanding of you. But I’m not looking for a search plugin, I’m trying to develop a select, search is something like the plugin mentioned but anything more specific. Let me give you an example straight down:

    This select below search the posts a post whose custom field exists other than NULL, if he finds one or more, it lists within the select option. A custom post type value for trading (sale, lease, barter). DISTINCT, without repeated values and status of published ok?

    <select name="negotiation" id="negotiation">
    <option value="">Select the Negotiation</option>
    <?php
    global $wpdb;
    $sql = "SELECT DISTINCT
    retorno.meta_value
    FROM
    ".$wpdb->posts." // IN ALL POSTS IN ALL NETWORK
    LEFT JOIN ".$wpdb->postmeta." AS retorno ON retorno.post_id = ".$wpdb->posts.".ID // IN ALL POSTS IN ALL NETWORK
    WHERE
    retorno.meta_key = 'negotiation' AND
    retorno.meta_value <> '' AND
    ".$wpdb->posts.".post_status = 'publish'
    ORDER BY
    retorno.meta_value ASC";
    foreach($wpdb->get_results($sql, OBJECT) as $rss){
    ?>
    <option value="<?=$rss->meta_value?>"<?php if($_GET['negotiation'] == $rss->meta_value){ ?> selected="selected"<?php } ?>><?=$rss->meta_value?></option>
    <?php } ?>
    </select>

    The question is do they get (sale, lease, barter) throughout my network and return the value of all posts on the network that have any of the values (sale, lease, barter). If the site 1 own some post that has the custom field negotiation with any value between “sale, lease and Exchange”, it pulls, if the site 2 own some post that has the custom field negotiation with any value between “sale, lease and exchange”, it pulls..

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘MySQL Select in all blogs of network’ is closed to new replies.