PluginProbe
Import WP – CSV & XML Import Export for WordPress / 2.8.1
Import WP – CSV & XML Import Export for WordPress v2.8.1
2.15.1 2.15.0 2.14.24 2.14.23 2.7.0 2.7.1 2.7.10 2.7.11 2.7.12 2.7.13 2.7.14 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.9.0 2.9.1 All 144 releases
jc-importer / functions.php

functions.php in Import WP – CSV & XML Import Export for WordPress 2.8.1, at functions.php

90 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 function iwp_fn_get_posts_by($input = '', $field = 'post_title', $post_type = 'post')
3 {
4 $core_fields = array(
5 'ID',
6 'menu_order',
7 'comment_status',
8 'ping_status',
9 'pinged',
10 'post_author',
11 'post_category',
12 'post_content',
13 'post_date',
14 'post_date_gmt',
15 'post_excerpt',
16 'post_name',
17 'post_parent',
18 'post_password',
19 'post_status',
20 'post_title',
21 'post_type',
22 'tags_input',
23 'to_ping',
24 'tax_input'
25 );
26
27 $query_vars = array(
28 'post_name' => 'name',
29 'ID' => 'p'
30 );
31
32 $parts = array_values(array_filter(array_map('trim', explode(',', $input))));
33 $output = [];
34 foreach ($parts as $part) {
35
36 $query_args = array(
37 'post_type' => $post_type,
38 'post_status' => 'any, trash, future',
39 'fields' => 'ids',
40 'cache_results' => false,
41 'update_post_meta_cache' => false,
42 'update_post_term_cache' => false,
43 'no_found_rows' => true,
44 );
45
46 if (in_array($field, $core_fields, true)) {
47
48 if (array_key_exists($field, $query_vars)) {
49 $query_args[$query_vars[$field]] = $part;
50 } else {
51 switch ($field) {
52 case 'post_title':
53 $query_args['title'] = $part;
54 break;
55 default:
56 $query_args[$field] = $part;
57 break;
58 }
59 }
60 } else {
61 $meta_args[] = array(
62 'key' => $field,
63 'value' => $part
64 );
65 }
66
67 if (!empty($meta_args)) {
68 $query_args['meta_query'] = $meta_args;
69 }
70
71 $query = new \WP_Query($query_args);
72 if (count($query->posts) === 1) {
73 $output[] = $query->posts[0];
74 }
75 }
76
77
78 return implode(',', $output);
79 }
80
81 function iwp_fn_prefix_items($input = '', $prefix = '', $output_delimiter = ',', $input_delimter = ',')
82 {
83 $items = explode($input_delimter, $input);
84
85 $items = array_map(function ($item) use ($prefix) {
86 return $prefix . trim($item);
87 }, $items);
88
89 return implode($output_delimiter, $items);
90 }