drfu29983 2019-04-07 10:36
浏览 34

将mailster插件中函数get_last_post的顺序更改为自定义字段顺序

i want change the order of post from post_date that is the default wordpress order and is using by mailster plugin to custom fields created by ADVANCED CUSTOM FIELDS

i work with the last version of mailster and in wordpress 5

this is the code source that control the order of post inside the plugin

 public function get_last_post( $offset = 0, $post_type = 'post', $term_ids = array(), $args = array(), $campaign_id = null, $subscriber_id = null ) {

        global $wpdb;

        $args = apply_filters( 'mailster_pre_get_last_post_args', $args, $offset, $post_type, $term_ids, $campaign_id, $subscriber_id );

        $key = md5( serialize( array( $offset, $post_type, $term_ids, $args, $campaign_id, $subscriber_id ) ) );

        $posts = mailster_cache_get( 'get_last_post' );

        if ( $posts && isset( $posts[ $key ] ) ) {
            return $posts[ $key ];
        }

        $post = apply_filters( 'mailster_get_last_post_' . $post_type, null, $args, $offset, $term_ids, $campaign_id, $subscriber_id );

        if ( is_null( $post ) ) {

            $defaults = array(
                'posts_per_page' => 1,
                'numberposts' => 1,
                'post_type' => $post_type,
                'offset' => $offset,
                'update_post_meta_cache' => false,
                'no_found_rows' => true,
                'cache_results' => false,
            );

            if ( ! isset( $args['post__not_in'] ) ) {
                $exclude = mailster_cache_get( 'get_last_post_ignore' );

                if ( ! $exclude ) {
                    $exclude = $wpdb->get_col( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = 'mailster_ignore' AND meta_value != '0'" );
                }

                if ( ! empty( $exclude ) ) {
                    $args['post__not_in'] = (array) $exclude;
                }
            }
            $args = wp_parse_args( $args, $defaults );

            mailster_cache_set( 'get_last_post_ignore', $exclude );

            if ( ! empty( $term_ids ) ) {

                $tax_query = array();

                $taxonomies = get_object_taxonomies( $post_type, 'names' );

                for ( $i = 0; $i < count( $term_ids ); $i++ ) {
                    if ( empty( $term_ids[ $i ] ) ) {
                        continue;
                    }

                    $tax_query[] = array(
                        'taxonomy' => $taxonomies[ $i ],
                        'field' => 'id',
                        'terms' => explode( ',', $term_ids[ $i ] ),
                    );
                }

                if ( ! empty( $tax_query ) ) {
                    $tax_query['relation'] = 'AND';
                    $args = wp_parse_args( $args, array( 'tax_query' => $tax_query ) );
                }
            }

            $args = apply_filters( 'mailster_get_last_post_args', $args, $offset, $post_type, $term_ids, $campaign_id, $subscriber_id );

            $posts = get_posts( $args );

        } else {
            $posts = array( $post );
        }

        if ( $posts ) {
            $post = $posts[0];

            if ( ! $post->post_excerpt ) {
                if ( preg_match( '/<!--more(.*?)?-->/', $post->post_content, $matches ) ) {
                    $content = explode( $matches[0], $post->post_content, 2 );
                    $post->post_excerpt = trim( $content[0] );
                }
            }

            $post->post_excerpt = mailster( 'helper' )->get_excerpt( ( ! empty( $post->post_excerpt ) ? $post->post_excerpt : $post->post_content), apply_filters( 'mailster_excerpt_length', null ) );

            $post->post_excerpt = apply_filters( 'the_excerpt', $post->post_excerpt );

            $post->post_content = apply_filters( 'the_content', $post->post_content );

        } else {
            $post = false;
        }

        if ( ! isset( $args['cache_results'] ) || $args['cache_results'] !== false ) {
            $posts[ $key ] = $post;

            mailster_cache_set( 'get_last_post', $posts );
        }

        return $post;
    }

i try this but i don't know when i can put it this code and how to creat custom function to change the code

 $args = array(
      'post_type' => 'post',
      'order' => 'ASC',
      'meta_key'=>'post_position'
      'orderby'=> 'meta_value',

  );
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?
    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
    • ¥15 Arduino无法同时连接多个hx711模块,如何解决?