and here is the solution ..
adding the following in the theme’s functions.php
add_filter( ‘wp_insert_post_data’, ‘wp_insert_post_data_filter’,1, 2 );
function wp_insert_post_data_filter( $data, $postarr ) {
@ $data['test_col'] = $postarr['custom_data'];
return $data;
}
.. where ‘test_col’ is the column name from wp_posts
i have put the @ in front of lines because I use it to post via XMLRPC and i was getting some errors while i was not submitting all the values for all variables.
i hope this thing is useful for others
Hi, I am having very similar problem I would love to solve.
I have in my wp_posts table a column called post_region
so when querying from a search form ($search_query contains the search term as in [s] => search term) my array will be.
$array2 = array(
'post_region' => '4'
);
$search_query = array_merge((array)$search_query, (array)$array2);
query_posts($search_query );
The search query comes through fine but post_region is ignored, I assume the code you have provided maybe registers the new column but I can’t get it to work.
SO say for example I include ‘post_type’ => ‘post’
That gets recognised, so my code is fine apart from obviously the that query_posts() function isn’t setup to recognise it.
Any idea’s thanks
I found the solution here
http://ww.wp.xz.cn/support/topic/wp_query-filters-1?replies=3
using the query filter posts_where
Strangely when I apply a filter it will display all the post types/ ie pages/revisons and posts in the results, whereas before it just displayed the posts.
It’s easy to set the filter to pagetype=whatever but something to look out for, I’m not sure I assume it does this as the posts_where writes over a certain part of the query
I’ve just realised that it overwrites the entire search query aswell
so my search items become balnk but my filters are recognised
global $query_string;
$query_args = explode("&", $query_string);
$search_query = array();
foreach($query_args as $key => $string) {
$query_split = explode("=", $string);
$search_query[$query_split[0]] = urldecode($query_split[1]);
} // foreach
//applying filters somewhere here the search query becomes lost
$search = new WP_Query();
add_filter('posts_where', 'filter_where');
$search->query($search_query);
// loop
if ($search->have_posts()) {
while ($search->have_posts()) {$search->the_post(); ?>
<?php include('/include/post_list.php') ?>
<?php } }
wp_reset_postdata();
?>
and in my funtions.php
function filter_where(){
$where .= "AND (wp_posts.post_region = '4')";
return $where;
}