Tag Info

New answers tagged

0

You can use the get_post_types function to fetch and search through the registered post types up to that point (the init hook where you would normally register the custom post type). You can possibly use a later hook like wp_loaded to do this check before trying to register the post type in case some other (not related to any of yours) plugin might have ...


0

In cases like this its better off (IHMO) to simple use a custom query using the $wpdb class ex: <?php global $wpdb; //first get a list of all meta keys $keys = $wpdb->get_col("SELECT distinct meta_key FROM $wpdb->usermeta"); //then prepare the meta keys query as fields which we'll join to the user table fields $meta_columns = ''; foreach ($keys ...


0

Your basic query logic looks fine assuming you want an AND relationship between the first, middle, and last names but query_posts is never, ever, ever the right way to do anything. Note: This function isn't meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is ...


0

you have to use "esc_attr" in case your value contains a quote for exemple <?php echo esc_attr(get_post_meta(...));?>


1

To add a meta box you have to use add_meta_box function which allows us to add meta boxes to the administrative interface.But just adding a meta box doesn't make it work. You must also have a callback function that prints out the HTML for the edit screen section. In your case we need that callback function to display an area where user has control of ...


0

Best method may be JAVASCRIPT: <script type="text/javascript"> var field_id = "My_field_div__ID"; // <----------------- CHANGE THIS var SubmitButton = document.getElementById("save-post") || false; var PublishButton = document.getElementById("publish") || false; if (SubmitButton) {SubmitButton.addEventListener("click", SubmCLICKED, ...


1

Here is a code snippet that will do what you described: add_action( 'pre_get_posts', 'wpsx_185734_acf_search_relationship' ); function wpsx_185734_acf_search_relationship( $q ) { $screen = get_current_screen(); $s = $q->get('s'); $post_type = $q->get('post_type'); // Be very selective when running code at the pre_get_posts hook ...


0

I will answer to my best ability point by point. Yes, wp multisite would be ideal for this and it will all be in one database. Not easy to do without a plugin, but yes there are plugins available for translations. However issues might arise, especially with regards to the customer's expectations. a) This can be a problem, as the translation plugins ...


0

If you want to be able to validate server side the easiest option is to use Advanced Custom Fields to define your custom field layouts, and then the Validated Field add-on to set your validation per field in the WordPress Admin.


-1

According to ACF Docs on Get values from an options page. You should use 'option' not 'options' as the second parameter to the have_rows() function. <?php if( have_rows('repeater', 'option') ): ?> <ul> <?php while( have_rows('repeater', 'option') ): the_row(); ?> <li><?php the_sub_field('title'); ...


0

If your dates are saved in the following format, Y-m-d, it is quite easy. Your year will stay the same, so your can then technically sort by month. All you need is to add the correct values to the order and orderby parameters. You can try the following // Query Post Type $args = array( 'post_type' => 'events', 'post_status' => 'publish', ...


0

here is the mysql query you can use to get the result having distance less then your value. SELECT * , pm1.meta_value as latitude, pm2.meta_value as longitude , (((acos(sin(([latitude]*pi()/180)) * sin((pm1.meta_value * pi()/180)) + cos(([latitude]*pi()/180)) * cos((pm1.meta_value * pi()/180)) * cos((([longitude] - ...


0

It seems that you could use Types and Views plugins (with Views "Parametric search" feature). Views is commercial, but unless you are building your personal website, I think it's worth it. Nice writeup about those plugins is, for example, here: http://www.neilcurtis.me/guides/best-wordpress-plugins/


0

It seems to me like this is just a regular addition to functions. Since you are asking, I think you may not be getting the result you are looking for. If this was my project, I would create a new plugin, install it into the regular plugin list so that it does not get overwritten anywhere and then add the new properties. Create a file called ...


0

It seems that at that point, $post is not yet defined, you can make sure by turning debugging on. Then add this before your get_post_meta( $post...: global $post; Or you can replace $post->ID with get_the_ID().


0

I've already faced this kind of matter, but my approach was quite different: I've created a sort of framework to do crud operation and manage totally new entities, each one different from others, using the wp db layer, supported by a custom db layer. In your case, I think is possible to do what you want but you need to use hook to intercept save post call, ...


1

add_action("admin_init", "admin_init"); add_action('save_post', 'save_reference_id'); /*** add_meta_box ***/ function admin_init(){ // adding a custom field to post type 'case' add_meta_box("refInfo-meta", "Reference", "meta_options", "case", "side", "high"); } /*** callback ***/ function meta_options(){ ?> <select name="page_id" ...


0

Ah, I see a few places where I went wrong. For one, in the switch statements, when I tried to return answers using echo, I was using parentheses, which work fine in one offs, but apparently cause an error in a function(?). Thanks to the one who edited my first code! I would not have seen that. So when I changed this: switch($graphic[0]) { case 1: ...


1

The second parameter to wp_set_object_terms() takes an array, integer, or string. (array/int/string) (required) The slug or id of the term (such as category or tag IDs), will replace all existing related terms in this taxonomy. To clear or remove all terms from an object, pass an empty string or NULL. Integers are interpreted as tag IDs. ...


2

Implode turns your array like this array( 'Audi', 'BMW', 'Mercedes-Benz' ) into a string separated by the delimiter set in the first parameter of the function, in this case , a comma and a space. In a way you can turn an array into a CSV from this. The result is this: Audi, BMW, Mercedes-Benz. The way WordPress works, it looks for an existing term (within ...


1

Normally Wordpress does not run shortcode that you put into a custom field. By default, Custom Fields display whatever value you enter, as plain-text, so if you try entering a shortcode, (in the format [shortcode] VALUE [/shortcode]) you’ll end up displaying the entire text, including the tags. Add the following in your template file, it can be single.php ...


0

This is how to do it for all post types: add_action( 'do_meta_boxes', 'remove_default_custom_fields_meta_box', 1, 3 ); function remove_default_custom_fields_meta_box( $post_type, $context, $post ) { remove_meta_box( 'postcustom', $post_type, $context ); }


2

I did similar thing recently but used the wp.media instead of ThickBox https://codex.wordpress.org/Javascript_Reference/wp.media with the same code from Codex. The only thing to make it work with multiple inputs is to move the frame variable from global scope to click function, so the 'frame' will be fresh for each click.


1

This should do it: <?php $rows = get_field( 'image_advert_repeater', 'options' ); // Wrap in an if statement to prevent an empy image SRC if no rows exist if ( ! empty( $rows ) && is_array( $rows ) ) { // Get the row and ranomise $rand_row = $rows[ array_rand($rows) ]; // get the image url from the array $rand_row_image = ...


0

Just noticed the issue - since your ACF field is an options page, you need to pass the second argument options to get_field - add a bit of sanity checking too: $rows = get_field( 'image_advert_repeater', 'options' ); if ( ! empty( $rows ) && is_array( $rows ) ) { // Your code }


0

I finally figured this out. The Custom Meta Boxes and Fields plugin has a sanitize setting where you can add your own sanitize function or use one of the default wordpress sanitize functions. In my case, Wordpress already has a sanitize function that does exactly what I wanted. See the code below, specifically the line "'sanitization_cb' => ...


1

If it's created with ACF, then the way to call the field is like this: $can_download = get_field('enable_downloads',$postid); so your code should look like: <?php global $wp_query; $postid = $wp_query->post->ID; $can_download = get_field('enable_downloads',$postid); if ($can_download == 'yes') { ...


0

Most important failure of WordPress is their database design. Its only useable for hosehold websites. High-performance sites will never use Anti-pattern as database design due to performance issues like BASIC indexing!


0

From the codex page You must pass 2 for the $accepted_args variable in add_filter() if you want to access $postarr. So use this: add_filter( 'wp_insert_post_data', 'set_post_title', 99, 2 );


0

display_schools($string); function display_schools($string) { $counter = 0; $i = 0; $len = count($string); foreach($string as $school) { if($counter == 0) { echo '<div class="row">'; } ?> <div class="col-xs-2"> <img src="<?php echo $school['photo']; ?>" ...


0

I found out a way to do this , turned out to be kind of easy here is what i did $Aschools = get_post_meta( get_the_ID(), 'american_member_schools_field', true ); $i = 0; $entries = count($Aschools); foreach ( (array) $Aschools as $key => $Aschool ) { $logo = $Aname = ''; $i++; if ( isset( $Aschool['name'] ) ) $Aname = $Aschool['name'] ...


0

Try this: get_post_meta(get_the_id(),'hjemmeside', true); Assumes hjemmeside is the name of your custom field key.


0

Don't let the fields be set to null or unset altogether. The queries needed to get that data are not efficient. Set your field to "no" or some other value. function save_details(){ global $post; if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post->ID; } $valid = array( 'yes' => 'yes', 'no' => 'no' ); ...



Top 50 recent answers are included