8000 Post query, list, and Meta fixes by midweste · Pull Request #64 · mehrshaddarzi/wp-trait · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Post query, list, and Meta fixes #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

midweste
Copy link
Contributor

implement query from old post class, add list function for backward compat, fix meta only and except warning.

After pulling the newest master version, I needed to implement a couple things that I used in some plugin implementations that use wp-trait.

I took the old post query implementation and adjusted it to allow for static implementation. I removed the post_type from the default params, and switched the order for wp_parse_args to apply args on top of defaults. Added list function that returns $query->posts if not empty.

The meta class I changed because when feeding in:
$meta = $this->post->find($block->ID)->meta()->only(['hook', 'priority']);

the only method was using func_get_args() which nested the array:
0 => [
0 => 'hook',
1 => 'priority'
]
This caused the array flip to complain as it was trying to flip 0 => array

Not sure about the static? Any suggestions there?

Copy link
Owner
@mehrshaddarzi mehrshaddarzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Query is a static method , do you get any error?

@midweste
Copy link
Contributor Author

I get no errors from using query through the newly added list($args) method

@midweste
Copy link
Contributor Author
midweste commented Dec 31, 2024

I only made two changes to the old Post query version:

  1. Comment out the default post type - If you're using query I don't think it really applies, if someone uses query without a post type, they should get all post types that match the arguments imho

         $default = [
             // 'post_type' => $this->type,
             'post_status' => 'publish',
             'posts_per_page' => '-1',
             'order' => 'DESC'
         ];
    
  2. Changed the order of parse_args to have ($default, $args)

$args = wp_parse_args($default, $arg);

The only non static reference was $this->type in the defaults

@midweste
Copy link
Contributor Author

I'm going to change the parse args back. The signature is ($args, $defaults). I thought it was opposite.

fix parse args order
@midweste
Copy link
Contributor Author

Ok, parse args is fixed

@midweste
Copy link
Contributor Author

I'm on the fence about leaving a default for post_status. I think intuitively leaving it off makes sense, but having it as a default also makes sense. My concern would be as a developer, if you specify the args, I'm not sure you would expect published to be added.

It would be a breaking change though

@midweste
Copy link
Contributor Author

Anything you want me to look at changing here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0