Ante todo gracias por brindar a devoloper un foro de consulta. WordPress sin duda haceis un gran trabajo todos y toda la comunidad.
Disculparme si este post no esta bien colocado, espero poder seguir aportando y que me podais aportar luz en el camino de un pleno desarrollo.
Os comento, el problema que tengo es algo complicado incluso de hacer entender, pero estoy mas que bloqueado desde hace dias. (Y si no consigo salir de este agujero con alguna solución, en mi empresa buscaran a otro :S )
Información general:
Problema:
– La idea que quiere el cliente es que el tendra accesso al Superadmin para manipular cada uno de los Blogs que cuelgan del general, esto sin problema esta realizado. El problema vienen que en el blog 1 si creas un posts del portfolio y seleccionas (el form) que quieres que sea visible en el blog 2 y 3, esto cuando se guarda lo almacena en mi tabla para que quede constancia.
En el listado de post del blog 1, saldra el creado en el Blog 1, pero si me voy en listado del Blog 2, deberia verse los posts creado en el mismo blog y los de los otros blogs que han seleccionado en el form que se vieran (pero estos posts no serian editables en el blog 2, sino en el blog de procedencia), es decir, solo se listarian los posts del mismo blog mas el de los otros.
Codigo hasta ahora: (listar los blogs es posible ya que los tengo en un array)
add_action( 'pre_get_posts' ,'include_this_portfolio' );
function include_this_portfolio( $query ) {
global $blog_id;
//Si no es admin lista normal
if( !is_admin() )
return $query;
global $pagenow;
//Si la pagina es edit, visualiza. Para filtrar que no se vea en otras paginas.
if( 'edit.php' == $pagenow && ( get_query_var('post_type') && 'portfolio' == get_query_var('post_type') ) ){
$query->set( 'post__in', array(37) ); // array page ids Incluye
}
return $query;
}
Posible sugerencia:
Usando,
switch_to_blog() ->Cambiamos de blog.
pre_get_posts -> Editamos la funcion del listado
loop_start -> Recorrer todos los blogs
restore_current_blog()-> restaurar al blog actual
add_filter(posts_results -> Para visualizar todo el listado creado.
Con todo esto debería conseguirlo me supongo, pero ya estoy perdido.
Alguien me podría ayudar con alguna luz en el camino, antes que me despidan.
Saludos y mil gracias de antemano.
atte.Gerard
]]>I tried wp_head, but that’s in the header not the body.
I tried loop_start, but many themes seem to execute too many loops, so for instance with the thematic theme, my material appears twice in the header and once in the body. With certain widgets it can then appear again in the sidebar.
Any ideas?
]]>I’ve tried hooking into loop_start, but the main loop is already started by the time it is triggered and this causes problems (not to mention the infinite recursion when the inner loop triggers loop_start 8=)
What actions can I look at to get my loop put in the right place? I need wp_query to be run so that I know what the page type is (i.e. is_home() needs to work properly).
I want this to work with any theme that uses a standard loop for the home page.
]]>Very simply, i use an add_action and within the function i call a wpdb->update. I print the value just before and just after it writes to the database and the echo is correct. However when i look in the database with phpmyadmin i see that whatever the SQL i used, it doubles itself. So if I try to increment a column by 1, it does it twice. If i use an insert, it inserts it twice. Even if I put a die straight after it, it still does it <:(
Here is the code exactly as it is:
add_action( "loop_start", "start" );
function start( $post )
{
global $wpdb;
$USER_ACHIEVEMENTS_DB = $wpdb->prefix.PG_USER_ACHIEVEMENTS;
$userAchievement = $wpdb->get_row("SELECT * FROM $USER_ACHIEVEMENTS_DB WHERE achievement = 'Explorer' AND user_id = 1");
$currentScore =(int)$userAchievement->score;
//Print just before
echo "before $currentScore";
$currentScore += 1; //increment
//Call the update
$wpdb->update( "$USER_ACHIEVEMENTS_DB", array( 'stage' => 1, 'level' => $currentScore, 'score' => $currentScore ),
array( 'user_id' => 1, 'achievement' => "Explorer" ),
array( '%d', "%s", '%d', ),
array( '%d', '%s' ));
echo "after $currentScore"; //This is correct. but in the DB its always double what I increment it with.
die("FIN");
}
]]>function add_special_posts($posts) {
global $wpdb;
if (is_category('11')) {
$my_table_name = $wpdb->prefix . "posts";
$sql_select = "SELECT * FROM " . $my_table_name;
$result = $wpdb->get_results($sql_select, ARRAY_A);
$posts = array();
foreach ($result as $mytable_value) {
$post = new stdClass();
$post->ID = $mytable_value['id'];
$post->post_author = '1';
$post->post_date = date('Y-m-d H:m:s');
$post->post_type = 'post';
$post->post_title = $mytable_value['portfolio_name'];
$post->post_content = $mytable_value['full_description'];
$post->post_status = 'open';
$post->comment_status = 'open';
$post->ping_status = 'open';
$posts[] = $post;
}
}
return $posts;
}
It works fine: i get posts list from my specific table in category with id=11. Now I want to view a single post page with data from my_table_name. I suspect that I use the_post action hook or may be loop_start action hook.
When I use something like as:
function view_single_special_post($post) {
global $wpdb;
if (is_single() && in_category('11',$post->ID)) {
$portfolio_table_name = $wpdb->prefix . "portfolio";
$sql_select = "SELECT * FROM " . $portfolio_table_name;
$result = $wpdb->get_results($sql_select, ARRAY_A);
foreach ($result as $mytable_value) {
$post->ID = $mytable_value['id'];
$post->post_author = '1';
$post->post_date = date('Y-m-d H:m:s');
$post->post_type = 'post';
$post->post_title = $mytable_value['portfolio_name'];
$post->post_content = $mytable_value['full_description'];
$post->post_status = 'open';
$post->comment_status = 'open';
$post->ping_status = 'open';
}
}
return $post;
}
add_action('the_post', 'view_single_special_post');
It doesn’t work for category wiht id=11, which has data from my specific table $my_table_name, but works for other categories. I write it at the plugin file.
Help me please and sorry for my English.
]]>