How to get Relationship Field dual-column showing IDs instead of post titles in ACF plugin?

by default, in the ACF plugin, the relationship field allows the user to choose a relation with another post in the default dual column view. In my case, I am using the Relationship field in order to connect dealer post-types to products.

Since I am importing Product data from CSV, I would need to import Relationship fields as well, and I am doing this using WP All Import Pro plugin. If I try to export a product in order to create the proper CSV format, I can see all set up relationships using the Dealer post-type title. I would need to type in CSV the dealers IDs instead of their full title, because the titles could change at some point.

Is that something possible through a function? Also, apart from dealers IDs, is it possible to achieve using another IDs set up using ACF (that is to say, another ID which is not the default one assigned by WP)?

For now, I am using Post Object return format, I’ve tried with Post ID return format but does not work (I am not sure if this could work since I am trying to do something out of my knowledge…).

Thank you in advance,
nflor

Save ACF relationship (name) value to ACF text field

I try to achieve the following.
I have two post types, “projects” & “kuenstlerinnen” (artists)
Within the post type “projects”, there’s an ACF relationship field setup, connecting these two to together → “project_to_kunstlerin”

The post-type “künstlerinnen” (Artists) contains two ACF text fields:
first-name (“artist_vorname”) & Last- or Group-Name (“artist_nachname”). There is a code snippet running, which saves both fields to the title → “artist_vorname””artist_nachname”

I know would like to have a hidden text field within the projects post type, which is automatically populated with the first value of the “project_to_kunstlerin” field. It should only use the last name field. The reason I try to get this to work, is that I can order by this hidden field, so I get the posts ordered by the last name of the artist.

So far I come up with the following code-snippet:

<?php

//Make special artist field autosave for sorting
function write_artist_name_to_hidden( $post_id ) {
    $post_type = 'projects'; //custom post type for events
  
    //Check if we are saving correct post type
    if( get_post_type( $post_id ) != $post_type)
      return;
  
    //Check it's not an auto save routine
    if( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) 
      return;
    
    // get the artist id  of the post. Note this is in a relationship field
    $nameofartist = get_post_field ('project_to_kunstlerin', $post);
    
  
    // update the artist value 
    update_field( 'project_kunstlerin_nach_name_sort', $nameofartist, $post_id );
  }
  add_action('save_post', 'write_artist_name_to_hidden');

In the backend, it now populates the destination ACF field with:

One artist: “(“37″)”
Two artists: (“37″,”38”)

These are the IDs.

How can I get another value there instead of the post id?

In theory, it must be something like:

  1. Check with IDs are in the “project_to_kunstlerin” relationship field.
  2. Take the first ID.
  3. Look up, which value is stored in “artist_nachname” of ID in post type “kuenstlerinnen”

Maybe anybody of you has an idea how to get this to work?
Your help is highly appreciated!

What's the Point of having a Relationship for you personally?

As a sex-repulsed aro-ace, I don’t have to have someone else make me happy, as I do always find something to do on my own, I’m stressed out in relationships for me personally.

filters – ACF Relationship Previous Next links of CPT

I have a CPT for artworks with custom taxonomy for artists. Then I have another CPT for artists. The artist pages are basically the the page title (artist name) and a relationship field where you add the artist’s artwork from the artworks CPT where you can filter by the custom taxonomy (since there are 50+ artists and 100s of artworks).

Each artwork is its own page as mentioned. When you click on the artwork from an artist page, we want to have the option of going to the next or previous artwork based on the order displayed on the artist page as determined by the order you set from its relationship field.

I’ve tried many solutions but none have worked yet. The only way I even get a hint of success is by adding a ACF field to the artworks post type that selects the artist post type via a post object field. I was using THIS PAGE as my guide.

There seems to be an issue with the following code. I’m note sure how $current_post_id applies to the array_search. If I print_r $current_index nothing appears. Same goes for $prev_module and $next_module. However, if I print_r $module_ids the array appears as it should in the order I set on the Artist page in the Relationship field. $first_module and $last_module show the correct IDs too. I just can’t seem to get the current post ID to then determine next and previous.

// create empty array for module ids
$module_ids = array();
             
// loop through modules and add them to array
foreach( $modules as $module ) :
    $module_ids() = $module->ID;
endforeach;
             
// get the current index
$current_index = array_search( $current_post_id, $module_ids );
             
// find the prev/next items
$prev_module = $current_index - 1;
$next_module = $current_index + 1;
             
// find first and last modules
$first_module = $module_ids(0);
$last_module = end($module_ids);

postgresql – Postgres per-statement update trigger relationship between old and new transition tables

Is there anyway to associate rows between the old transition table and new transition table for a per-statement update trigger in Postgres? docs

My use-case is that I have a “shadow” table of an existing, concrete table. I’d like to update the shadow table on every UPDATE statement on the concrete table. I know I can use a per-row trigger to accomplish this. Can I use a per-statement trigger instead?

As a concrete example on Postgres 13.3, I’d like something like:

CREATE TABLE product (id bigint, val text /* many more columns */);
CREATE TABLE shadow_product (id bigint, val text);

CREATE FUNCTION update_shadow_product() RETURNS trigger AS
$fn$
DECLARE
  old_data text;
  new_data text;
BEGIN
  UPDATE shadow_product
  SET id = t.old_id, val = t.new_val
  FROM (
    -- How to handle case where ID changes between old and new?
    SELECT ot.id as old_id, nt.val as new_val  FROM oldtab ot
      INNER JOIN newtab nt USING (id)
  ) t
  WHERE id = t.old_id;

  RETURN NULL; -- per-statement triggers should always return null
END;
$fn$ LANGUAGE plpgsql;


CREATE TRIGGER update_shadow_products_trigger
  AFTER UPDATE ON product
  REFERENCING NEW TABLE AS newtab OLD TABLE AS oldtab
  FOR EACH STATEMENT
EXECUTE FUNCTION update_shadow_product();

As a test case:

-- Seed initial data.
INSERT INTO product (id, val) VALUES (1, 2), (10, 20);
INSERT INTO shadow_product SELECT id, val FROM product;

-- Update the primary key which makes it hard to match old to new rows.
UPDATE product SET id = 2 * id WHERE TRUE;

-- Show rows that differ between product and shadow_product.
-- Ideally there's no null values, indicating the tables are the same.
SELECT p.id, p.val, sp.id AS shadow_id, sp.val AS shadow_val
FROM product p
  FULL OUTER JOIN shadow_product sp USING (id, val)

/*
 *  Returns:
 *
 *  +----+----+---------+----------+
 *  |id  |val |shadow_id|shadow_val|
 *  +----+----+---------+----------+
 *  |NULL|NULL|1        |2         |
 *  |2   |2   |NULL     |NULL      |
 *  |NULL|NULL|10       |20        |
 *  |20  |20  |NULL     |NULL      |
 *  +----+----+---------+----------+
 */

I’m not sure sure how to associate rows between oldtab and newtab if primary key changes. One thought I had was relying on row_number on oldtab and newtab without an order clause. Some quick tests seem to indicate the row_number order is stable but I’d prefer a more bulletproof method. Is there a better way?

linux kernel – Understanding buff/cache and tmpfs relationship on a read only filesystem with no swap

We have a really strange bug where a Yocto operating system running on a Raspberry Pi will ‘lock up’ because of disk IO wait.

Scenario:

  • operating system runs read only and has no swap
  • there is a tmpfs filesystem for stuff the OS needs to write to (/var, /log etc)
  • the tmpfs has default to half of the available 2GB of RAM
  • there is a USB hard drive connected for storing large MP4 files

After a while of running a Python program interacting with a Google Coral USB accelerator, the output of top is:

output of top command

So the CPU load is massive but the CPU usage is low. We believe this is because it is waiting for IO to the USB hard disk.

Other times we will see even higher cache usage:

Mem: 1622744K used, 289184K free, 93712K shrd, 32848K buff, 1158916K cached
CPU:   0% usr   0% sys   0% nic  24% idle  74% io   0% irq   0% sirq
Load average: 5.00 4.98 4.27 1/251 2645

The filesystem looks fairly normal:

root@ifu-14:~# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                 3.1G    528.1M      2.4G  18% /
devtmpfs                804.6M      4.0K    804.6M   0% /dev
tmpfs                   933.6M     80.0K    933.5M   0% /dev/shm
tmpfs                   933.6M     48.6M    884.9M   5% /run
tmpfs                   933.6M         0    933.6M   0% /sys/fs/cgroup
tmpfs                   933.6M     48.6M    884.9M   5% /etc/machine-id
tmpfs                   933.6M      1.5M    932.0M   0% /tmp
tmpfs                   933.6M     41.3M    892.3M   4% /var/volatile
tmpfs                   933.6M     41.3M    892.3M   4% /var/spool
tmpfs                   933.6M     41.3M    892.3M   4% /var/lib
tmpfs                   933.6M     41.3M    892.3M   4% /var/cache
/dev/mmcblk0p1           39.9M     28.0M     11.9M  70% /uboot
/dev/mmcblk0p4          968.3M      3.3M    899.0M   0% /data
/dev/mmcblk0p4          968.3M      3.3M    899.0M   0% /etc/hostname
/dev/mmcblk0p4          968.3M      3.3M    899.0M   0% /etc/NetworkManager
/dev/sda1               915.9G     30.9G    838.4G   4% /mnt/sda1

When it all ‘locks up’ we notice that the USB hard drive because completely unresponsive (ls does nothing and just freezes).

In the dmesg logs we have noticed the following lines (pasted as an image to preserve colours):

dmesg output

Here is a full output of dmesg after we start getting these errors:
https://pastebin.com/W7k4cp35

We are surmising that when the software running on the system tries to do something with a big file (50MB +) (moving it around on the USB hard drive), somehow the system is running out of memory.

We are really unsure how on earth we proceed. We found this blog: https://www.blackmoreops.com/2014/09/22/linux-kernel-panic-issue-fix-hung_task_timeout_secs-blocked-120-seconds-problem/ which kind of seems like the same problem and suggests modifying the vm.dirty_ratio and vm.dirty_background_ratio to flush caches to disk more often.

Is that the right approach?

The current settings are vm.dirty_ratio = 20 and vm.dirty_background_ratio = 10

Could a relatively slow USB hard drive require changing this? Can someone explain what is going on?

fa.functional analysis – Relationship between various notions of laws of random functions

Let $X,Y,Z$ be locally-compact metric spaces, $f:Xtimes Yrightarrow Z$ be uniformly continuous, and let $xi$ be an $X$-valued random element. Equip the set $C(Y,Z)$ with cylindrical $sigma$-algebra generated by the sets:
$$
C_{B,(y_1,dots,y_n)}:={f:Yrightarrow Z,|f(y_1,dots,y_n) in B},
$$

where $nin mathbb{Z}^+, , y_1,dots,y_nin Y,, Bin mathcal{B}(Z)^{otimes n}$.

What is the relationship between:

  • The law of the $C(Y,Z)$-valued random element $f(xi,cdot)$,
  • The pushforwards ${f(cdot,y)_{#}Law(xi)}_{y in Y}$
  • The pushforward $(xmapsto f(x,cdot))_{#}Law(xi)$?

Where $xmapsto f(x,cdot)$ denotes the map sending an $x in X$ to the function $ymapsto f(x,y)$ in $C(Y,Z)$

reference request – Relationship between spectral gaps of adjacency and Laplacian matrices of graphs

Let $G$ be an undirected simple graph on $n$ vertices, with self-loops allowed, and with arbitrary positive edge weights $w_{u,v}$ (which is $0$ if there is no edge between $u$ and $v$).

Let $A$ be the adjacency matrix of $G$, i.e. the rows and columns are indexed by vertices of $G$ and $A_{u,v} = w_{u,v}$.
Let $D$ be the diagonal degree matrix: $D_{u,u} = deg(u) = sum_v w_{u,v}$ and $D_{u,v} = 0$ for $u neq v$.
Let $L = D – A$ be the Laplacian matrix of the graph.

Both $A$ and $L$ are self-adjoint.
Let $mu_1 leq mu_2 dotsb leq mu_n$ be the eigenvalues of $A$, and let $0 = lambda_1 leq lambda_2 leq dotsb leq lambda_n$ be the eigenvalues of $L$.

I have run many tests, and it looks like the (top) spectral gap $mu_n – mu_{n-1}$ of $A$ is always at least as large as the (bottom) spectral gap $lambda_2 – lambda_1 = lambda_2$ of $L$.

The two quantities are equal if $G$ is regular, i.e. all vertices have the same degree, because then $D = deg(u) I$ for any vertex $u$ of $G$, and so the spectrum of $L$ is a shift and reflection of the spectrum of $A$.
In my tests, as the difference between the maximum and minimum degrees of $G$ gets larger (i.e. as $G$ becomes “less regular”), the difference $(mu_n – mu_{n-1}) – lambda_2$ gets larger as well (on average).
The relationship seems to be rougly linear.

It seems to me like this should be a known phenomenon (if indeed it is true), but I haven’t been able to find it anywhere in the literature. If anyone has seen this before, please let me know. Otherwise I’ll just try to prove it myself.

Plotting relationship between two variables when their relationship is given by a polynomial (2)

If you are getting an error, post the actual code used and the error message.

Clear("Global`*")

To Rationalize the polynomial you need to use the two-argument form Rationalize(#, 0)&. This will enable you to use whatever WorkingPrecision you need in the plot.

eqn = 62.77142857142857*(6.5 + 
         2*(18.57 - V))*(0.005*p*(18.57 - V) + (6.5 + 2*(18.57 - V))*V)*(0.01*
          p*(18.57 - V) + (6.5 + 2*(18.57 - V))*
          V)*(0.01*(0.65 + 0.01*(18.57 - V)) + 0.002275*(18.57 - V)*V) + 
      0.01*(65 + 0.0017499999999999998*(18.57 - V))*(18.57 - 
         V)*((6.5 + 2*(18.57 - V))*
          V*(0.005*p*(18.57 - V) + (6.5 + 2*(18.57 - V))*V) - (6.5 + 
            2*(18.57 - V))*V*(0.01*p*(18.57 - V) + (6.5 + 2*(18.57 - V))*V) + 
         2*(0.005*p*(18.57 - V) + (6.5 + 2*(18.57 - V))*V)*(0.01*
             p*(18.57 - V) + (6.5 + 2*(18.57 - V))*
             V))*(-0.05869954325800593*(18.57 - V) + 
         0.39*(6.5 + 2*(18.57 - V))*(0.01*(0.65 + 0.01*(18.57 - V)) + 
            0.002275*(18.57 - V)*V)) == 0 // Rationalize(#, 0) & // Simplify;

To get a feel for the range of V solve for a specific value of p

Solve(eqn /. p -> 1, V, Reals) // N

(* {{V -> 7.61125*10^-20}, {V -> 18.7221}, {V -> 21.8628}, 
    {V -> 142.557}, {V -> 37037.2}} *)

Manipulate(
 ContourPlot(Evaluate@eqn, {p, 0, 3}, {V, -1, vMax},
  WorkingPrecision -> 40,
  PlotPoints -> {25, 200},
  MaxRecursion -> 5, 
  FrameLabel -> (Style(#, 12, Bold) & /@ {p, V})),
 {{vMax, 25}, {25, 150, 40000}})

enter image description here

views – Eliminate results from a relationship (add an ON condition to JOIN)

I need to add an ON condition to a views JOIN. I cannot use a contextual filter, as it will filter out results altogether, and I need to get a result regardless (there are other joins). So I need to ensure the filter happens on the JOIN, and not as a WHERE condition.

To be more specific, I want to show a value when no relationship exists. The relationship is from one NODE type to another NODE of the same type, and I don’t want the current node retrieved. So the ON condition should be AND join_table.id != original_table.id.

I’m new to altering views queries. Can anyone provide assistance either on how to add an ON condition to a Views query either through the admin UI (if possible) or through a query alter?

Thank you