Nox
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: Queries results are mixed in add_filter(‘views_edit-post’)Thank you very much, I’ve just replaced the hardcoded date by my variable, and it works fine.
As you can see, the main issue with your effort is you did not properly relate the postmeta table with INNER JOIN.
I was a bit rusty on SQL, but I should have though of… it was a part of code that I found on internet, I badly broke it down. Thank you again for your advices.
Forum: Developing with WordPress
In reply to: Queries results are mixed in add_filter(‘views_edit-post’)Hi,
Thank you for your help.
It is difficult to find complex examples to use with $wpdb… I never used it before. I tried something, but it doesn’t return the excpected results :$date_limit = date('Y-m-d', strtotime("-8 days")); $rows = $wpdb->get_results($wpdb->prepare( " SELECT $wpdb->posts.* FROM $wpdb->posts, $wpdb->postmeta WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id AND ( ( $wpdb->postmeta.meta_key = %s AND $wpdb->postmeta.meta_value > %s ) OR ( $wpdb->postmeta.meta_key = %s AND $wpdb->postmeta.meta_value = %s ) ) AND $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'vehicle' ", 'date_sell', $date_limit . ' 00:00:00', 'date_sell', '' )); var_dump($rows);
I got 35 lines instead of 21 with that, moreover the posts don’t match with the conditions. I presume I make a mistake somewhere.
Can you help me to convert my WP_query into SQL request ?- This reply was modified 5 years, 10 months ago by Nox.
Forum: Developing with WordPress
In reply to: Query string URL parameter in wp-admin custom page ?Hi,
If you still would rather set an official added query var, you must white list it through the “query_vars” filter. Even so, WP will not have any idea what to do with this. You need to translate it into proper WP_Query arguments. Do so in the “pre_get_posts” action. All post queries pass through here, so be sure you only alter applicable queries. Depending on where the years are stored, you probably will be composing a meta_query argument.
Yes, that’s what I was referring to when I was talking about other attempts in my first reply. I usually use the “query_vars” filter in order to manage queries in templates (front side) (also usefull to pass parameters through template parts), it works fine, but I didn’t manage to make it work on admin interfaces.
If it’s alright to pull my query from the $_GET array, I think I’m going to stay with this solution.
vehicles, you will likely find meta queries taking a very long time. For large queries involving custom data, it’s more efficient to keep the data in a custom table with each type in its own column. You can still use the normal WP_Query process by altering the SQL through the “posts_request” filter. But if efficiency is important, you’re better off querying directly through global $wpdb, then looping through the results for output.
Yes. I also thought about this issue…
I already “optimized” my queries in order to display the vehicles list for the selected year (queries args with relations, and a few template which use the query result as parameter instead of call it again). In comparison, this is a heavy treatment to retrieve only some years…
As I said I’m not a backend developer so this sound very tricky for me to search and register available years in a independent table in database. I currently use ACF Pro to add and stock those data relative to each vehicle in my vehicle post-type.
I’d like to learn how to do it, maybe over time, but unfortunately we have binding deadlines with this project.Thank you for those details,
N.
- This reply was modified 6 years, 2 months ago by Nox.
Forum: Developing with WordPress
In reply to: Query string URL parameter in wp-admin custom page ?I’ve been stucked all morning, so I finally resolved to use the native PHP $_GET[”] variable.
$sellyear = $_GET['sellyear'] ? $sellyear = $_GET['sellyear'] : 2018;
When I call it in my the function which display the admin page (which is call by add_submenu_page method), it seems to work.
However, the way I tried the filter above (the one in my first post) it returns an empty string (”).I know it should not be the most correct way, but I didn’t find another way.
I stay open if you have something to propose me.Thank you for your help,
N.
Forum: Developing with WordPress
In reply to: Query string URL parameter in wp-admin custom page ?Hi Joy,
Thank you for your help.
Yes, I tried with different filter tags and priorities, but the result was always the same.
Even if I don’t try to get the query var (just set it), I got some errors pointing the wp-includes folder. I don’t even know how to “wait” for $wp variable to be ready.
I notice that the filter works on front pages, but not on admin pages.I’m originaly not a backend developer, I apologize for my misunderstanding and my poor practice… ??
Forum: Developing with WordPress
In reply to: Sortable columns : Order by a treatment ?Hm, so I’d try to play with the “posts_resquest” filter if I come across a harder case.
Here the default behaviour with the column order clause seems to work, so I’ll avoid bulky code to do the same sorting in my case.Thank you for your help and those details.
- This reply was modified 6 years, 2 months ago by Nox.
Forum: Developing with WordPress
In reply to: Sortable columns : Order by a treatment ?Oh my god… I just realized that the pre_get_posts hook was just an optional stape.
Native sort behaviour seems to do the job.Tell me if I’m wrong, but, it automatically sorts the posts depending on the “pure” result (the string shown in the column DOM), in the alphabetically order ?
Forum: Fixing WordPress
In reply to: Override the comment_form function ?Oh, thanks you ! It works well.
I’m still taking my first step in theme development, so I didn’t really understand how the to use the filters and how to find them.
So I use the same process to hook and custom the “comment” field (here the fields array were just used to manage extra fields like authors, url).
I share the result, here’s an example where I custom all fields of the comment form (adding placeholder to the fields, and removing the “website” field by the way) :
<?php // Edit "extra"-fields (author, email, url...) of comment form add_filter( 'comment_form_default_fields', 'custom_comment_form_fields', 10 ); function custom_comment_form_fields( $fields ) { $commenter = wp_get_current_commenter(); $req = get_option( 'require_name_email' ); $html_req = ( $req ? " required='required'" : '' ); $fields['author'] = '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . '<input placeholder="' . __( 'Name' ) . '" id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" maxlength="245" ' . $html_req . ' /></p>'; $fields['email'] = '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . '<input placeholder="' . __( 'Email' ) .'" id="email" name="email" ' . 'type="email"' . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" maxlength="100" aria-describedby="email-notes" ' . $html_req . ' /></p>'; unset($fields['url']); return $fields; } // Edit the "comment" text-area add_filter('comment_form_defaults', 'custom_comment_field', 10); function custom_comment_field ($defaults) { $defaults['comment_field'] = '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea placeholder="' . _x( 'Comment', 'noun' ) . '" id="comment" name="comment" cols="45" rows="8" maxlength="65525" required="required"></textarea></p>'; return $defaults; }
N.
- This reply was modified 6 years, 4 months ago by Nox.
Forum: Fixing WordPress
In reply to: Override the comment_form function ?I don’t really get why my question was moved to the “Fixing” section…
Aren’t native templates modification in a from-scratch custom theme considered as development ?- This reply was modified 6 years, 4 months ago by Nox.
Forum: Developing with WordPress
In reply to: How to enqueue a script depending on another script ?My own response make me figure out that the problem came from the jQuery handle function. I presume that all the function called inside it aren’t considered as declared.
I removed it, and transform all $ symbols in my script into ‘jQuery’.
And it worked…Maybe it exists a more correct alternative to use the $ symbol ?
Forum: Developing with WordPress
In reply to: How to enqueue a script depending on another script ?Hi @bcworkz,
Sadly, it’s actually the opposite.
The script that I tried to pass in first posisition (the library) contains only functions which are not declared in a “on document ready” like method. They’re only surrounded with the jQuery handle function
(function($) { ... })( jQuery );
The second one is used for the treatment of animations on this specific “projects page”, and calls function of my lib : here the entiere script is surrounded in a ready function :
(function($) { $('document').ready(function(){ ... }) })( jQuery );
So its content should normaly be loaded after the first script (even after the entier DOM initialization).
- This reply was modified 6 years, 4 months ago by Nox.
Forum: Developing with WordPress
In reply to: How to enqueue a script depending on another script ?@jaycbrf this is exactly what I tried in the first example.
It didn’t work. :/Oh dear… How can I be so silly. I did not even notice that it was the same functions. Thank you & sorry.
Forum: Developing with WordPress
In reply to: Create unreachable CPT (only content management)Indeed, it seems to work fine with the ‘show-ui’ argument.
Thank to both of you for your helpForum: Developing with WordPress
In reply to: Create unreachable CPT (only content management)Hi,
Thank you for the fast answer. My bad, I already tried that, but my CPT disappeared from my admin menu when I did that. I though it was an argument to entierly disable the CPT (without delete it). Is there a way to take it back in the admin menu and still keep the “public: false” state ?
Edit : Finally used thoses args, seems to work.
'public' => true, 'has_archive' => false, 'exclude_from_search' => true, 'publicly_queryable' => false,